[英]SpringBoot embedded tomcat dependency
我使用spring初始化程序创建了一个简单的spring boot Web项目。 我有一个简单的项目设置,其中包括以下依赖项:
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
我使用JSP作为视图,因此在配置中添加了以下bean:
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
当我启动应用程序并转到主页时,但是,当我将以下JAR添加到我的类路径中时,出现404错误
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '7.0.77'
有用。 我的印象是Spring Boot Starter Web依赖项包括嵌入式tomcat,而我不需要单独添加它吗?
这是开始它的主要应用程序类:
@SpringBootApplication(scanBasePackages={"com.wsapp"})
@EnableWebMvc
@EnableAutoConfiguration
public class SampleApplication {
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
}
如果希望使用tomcat,为什么还要在依赖项中使用jersey?
compile('org.springframework.boot:spring-boot-starter-jersey')
我认为春季自动配置只是加载球衣配置。 Tomcat是默认的,但前提是您没有在依赖项中显式添加其他模块。 如果要使用tomcat,请尝试删除此依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.