我使用gradle和spring boot启动了一个新项目,我无法让JSP工作。当我执行请求时,我只看到日志中的错误
找不到带有URI [/WEB-INF/jsp/home.jsp]的HTTP请求的映射 DispatcherServlet,名称为“dispatcherServlet”
我已经看到很多类似堆栈溢出的问题,但是大多数问题与无效的xml配置有关......自从我使用spring boot以来我没有这个问题。
这是我的配置
的build.gradle:
buildscript {
ext {
springBootVersion = '1.2.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE")
}
}
group 'fi.achivi.server'
version '1.0-SNAPSHOT'
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
war {
baseName = 'achivi'
version = '0.0.1-SNAPSHOT'
}
jar {
baseName = 'achivi'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.cloud:spring-cloud-starter-eureka:1.0.1.RELEASE',
'org.springframework.boot:spring-boot-starter-web',
'org.springframework:spring-webmvc:4.1.6.RELEASE',
'org.springframework.boot:spring-boot-starter-data-mongodb',
'org.springframework.cloud:spring-cloud-config-client:1.0.1.RELEASE',
'jstl:jstl:1.2',
'commons-validator:commons-validator:1.4.1',
'org.springframework.security:spring-security-web:4.0.1.RELEASE',
'org.springframework.security:spring-security-config:4.0.1.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test',
'cz.jirutka.spring:embedmongo-spring:1.3.1', //mongodb dependencies
'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.48.0'
providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper:8.0.8'
}
application.properties
server.port=80
server.contextPath=
服务器
@Configuration
@SpringBootApplication
@EnableMongoRepositories
public class Server {
public static void main(String[] args) {
new SpringApplicationBuilder(Server.class).web(true).run(args);
}
@Bean
public MongoTemplate getMongoTemplate() throws Exception{
Mongo m = new MongoClient("localhost");
MongoTemplate template = new MongoTemplate(m, "achivi");
return template;
}
}
MVC配置 @组态 @EnableWebMvc 公共类WebConfig扩展了WebMvcConfigurerAdapter {
@Bean
public InternalResourceViewResolver setupViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
}
HomeController中:
@Controller
@RequestMapping("/")
public class HomeController {
@RequestMapping
public String entry() {
return "home";
}
}
然后是/src/main/webapp/WEB-INF/jsp/home.jsp中的jsp文件
我尝试访问http://localhost
下的应用根据我发现的所有教程,这应该可行。但它仍然没有。有什么想法吗?