0

I would build a Spring - Jnlp project with Maven shade plugin in order to output only one jar file. The project has one dependency referring to a secondary Spring project. The resulting jar structure shows correctly all the specified dependencies packages, classes and resources, including imported-application-context.xml placed in the archive root. Unfortunately Spring cannot load configured beans in imported file at execution time.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <!-- STUFF -->

  <dependencies> 
    <!-- SPRING AND SECONDARY PROJECT DEPENDENCIES --> 
  </dependencies>

  <build>   
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals><goal>shade</goal></goals>
            <configuration>
              <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <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>
              </transformers>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                  </excludes>
                </filter>
              </filters>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>  
  </build>

</project>


application-context.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true">

  <import resource="classpath:imported-application-context.xml"/>

  <bean id="myBean" class="myPackage.MyClass">
    <property name="myProperty" ref="importedBean" />
  </bean>
</beans>


exception

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'myBean' defined in the
classpath resource [application-context.xml]: 
Cannot resolve reference to bean 'importedBean' while 
setting property 'myProperty'; [...]
ruphus
  • 163
  • 1
  • 13

1 Answers1

0

I had a similar problem. For me the answer was to include the project that contained the 'imported-application-context.xml' as a dependency in my pom.

Not sure if you're still looking for the answer, or if this is the answer to your problem as well, but it might help someone else who encounters this problem.