- Maven shade with Spring Boot
The goal was to create an uber-jar out of the Spring boot application. Following the directions given at Apache went very smoothly yet when I tried to execute the jar a large number of spring beans were missing and not getting loaded during runtime. For example, one of the beans not getting loaded was 'AutoConfigurationPackages'
jar -tvf name.jar | grep AutoConfigurationPackages
showed that the class file was present in tha jar.
jar -xvf name.jar
to extract jar into the current directory.
java -cp . com.pq.Main
gave the same behavior as trying to run the executable jar.
Turns out the Spring jars have a number of directives ( things like mappings to XML Schema URIs to namespace handlers ) in each jar. Default behavior of shade is to overwrite those files.
Part of the solution was found on StackoverFlow. The other half was found in the Spring Boot issues
Here is what I needed to add to my pom to get things working.
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
</transformers>
This directs the maven shade plugin to append the spring.handlers from the various spring jars into one spring.handlers file in the uber-jar instead overwriting it with the latest spring jar seen. The same needed to be done with spring.schemas and spring.factories.
"missing spring boot" missing org.springframework.boot.autoconfigure.AutoConfigurationPackages