我无法理解为什么在以下最小项目中,我在Eclipse和IntelliJ中运行测试时发现了接口的弹簧WebApplicationInitializer
,但在使用Maven(mvn clean test
)时未找到接口。使用嵌入式Tomcat的Spring WebApplicationInitializer(ServletContainerInitializer,@HandlesTypes)
使用Eclipse和IntelliJ我看到INFO: Spring WebApplicationInitializers detected on classpath: [[email protected]]
随着mvn clean test
我看到INFO: No Spring WebApplicationInitializer types detected on classpath
。
在测试中我开始一个嵌入式的Tomcat:
String pathToWebXML = new File("src/main/webapp/").getAbsolutePath();
tomcat = new Tomcat();
tomcat.setBaseDir("embedded_tomcat");
tomcat.setPort(0);
tomcat.addWebapp("", pathToWebXML);
tomcat.start();
的web.xml
引用一个ServletContextListener
实现它创建了一个新的(空)AnnotationConfigWebApplicationContext
。
我上传的示例项目的GitHub:https://github.com/C-Otto/webapplicationinitializer
您在IntelliJ中使用的是什么版本的java。你使用java 8吗?我注意到在你使用java 8 –
@Periklis的pom文件中,我使用Java 8.你有没有看到我不运行Java 8的提示?我对你的问题感到困惑。 –
对不起,我只是想确保你在IntelliJ中使用的Java版本是你在pom.xml中定义的版本。每当我有时间我会下载你的应用程序,我会试一试 –