0

I am using org.glassfish.jersey.ext:jersey-spring3 for Injecting Spring Beans into Jersey JAX-RS resource class. Bean injection works fine except for this jar also contains SpringWebApplicationInitializer class which directly interferes with my own Custom WebApplicationInitializer. For testing purpose, I forcibly removed SpringWebApplicationInitializer from initializing in SpringServletContainerInitializer in Debug mode and my app runs fine.

I also tried maven-shade-plugin with following configuration

<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>

This plugins copies both jars and classes to WAR file. SO even though SpringWebApplicationInitializer.class was removed, original jar (which still contains SpringWebApplicationInitializer.class) was copied and SpringServletContainerInitializer is still picking up SpringWebApplicationInitializer class.

gnuger
  • 305
  • 2
  • 12
  • "Bean injection works fine expect" -> do you mean "Bean injection works fine **except**"? – Matthias J. Sax Aug 28 '15 at 20:04
  • "But all the jars are still copied in my app.war along with all the Class files except SpringWebApplicationInitializer.class ." What is the problem? You exclude this file and you "complain" that it's not in the jar. – Matthias J. Sax Aug 28 '15 at 20:05
  • Sorry for my bad english, what I meant was even though the class was removed in uncompressed version original jar was still copied to the war file which contains that class so SpringServletContainerInitializer is still picking up that class. – gnuger Aug 29 '15 at 13:16
  • No reason to apologize :) Just need to understand to problem correctly. How do you build your war file (can to add the corresponding pom.xml part to your question)? If you want to shade something in you war, you need to assembly the war using the shade plugin... – Matthias J. Sax Aug 29 '15 at 14:14
  • Here is my pom.xml : http://pastebin.com/XmwjKVCk – gnuger Aug 29 '15 at 15:19
  • You need to tell maven, that is should use the shaded jar instead of the original one. See https://maven.apache.org/plugins/maven-shade-plugin/examples/attached-artifact.html Also consider https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#finalName (I did not try it or used it by myself before. Let me know if it works.) – Matthias J. Sax Aug 29 '15 at 15:49
  • I tried this as well but it didn't work. I guess maven-war-plugin is copying the jars and maven-shade-plugin only works with jar packaging – gnuger Aug 29 '15 at 18:37
  • Maybe you can try maven-assembly-plugin.... https://maven.apache.org/plugins/maven-assembly-plugin/ to package you war. – Matthias J. Sax Aug 30 '15 at 15:10
  • Have a look at [this answer](http://stackoverflow.com/a/32357991/2587435). I think the first work around might work for you. There is a link to a complete example also – Paul Samsotha Sep 05 '15 at 15:56

0 Answers0