我使用org.glassfish.jersey.ext:jersey-spring3将Spring Beans注入Jersey JAX-RS资源类。 Bean注入工作正常,除了这个jar还包含SpringWebApplicationInitializer类,它直接干扰我自己的Custom WebApplicationInitializer。出于测试目的,我在调试模式下强制删除SpringWebApplicationInitializer初始化SpringServletContainerInitializer,我的应用运行正常。
我还尝试了以下配置的maven-shade-plugin
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>org.glassfish.jersey.ext:jersey-spring3</artifact>
<excludes>
<exclude>org/glassfish/jersey/server/spring/SpringWebApplicationInitializer.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
此插件将jar和类复制到WAR文件。即使SpringWebApplicationInitializer.class被删除,原始jar(仍然包含SpringWebApplicationInitializer.class)被复制,SpringServletContainerInitializer仍在使用SpringWebApplicationInitializer类。