使用Idea CE 创建了一个基于 Maven 构建的 Spring Boot 项目,在打包的时候提示:
无法访问javax.servlet.ServletException
完整错误信息:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project testboot: Compilation failure
[ERROR] /Users/aven/Documents/IdeaProject/testboot/src/main/java/Application.java:[10,8] 无法访问javax.servlet.ServletException
[ERROR] 找不到javax.servlet.ServletException的类文件
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Process finished with exit code 1
产生这个错误的原因:
项目打包成功后,部署到Tomcat启动失败。
在网上找到解决方案是:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- 使用嵌入式Tomcat作为web container -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
添加了 使用嵌入式Tomcat作为web container 部分后,再打包就出错了。
解决方法:
添加依赖
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
但这仅仅是解决了打包报错的问题,项目依然无法启动成功。
错误信息:
** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
2017-08-29 13:29:37.295 ERROR 15344 --- [ost-startStop-1] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [Application]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/batch/core/configuration/annotation/BatchConfigurer.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:180) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) ~[spring-context-4.3.5.RE