java - org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException in spring compiled Jar -


i have looked around , , have not found solution has solved issue me. have maven project using spring , call assembly-single , build runnable jar. project works fine ide when run runnable jar following exception:

org.springframework.beans.factory.xml.xmlbeandefinitionstoreexception: line 8 in  xml document class path resource [properties.xml] invalid; nested excep tion org.xml.sax.saxparseexception; linenumber: 8; columnnumber: 62; cvc-elt. 1.a: cannot find declaration of element 'beans'.         @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.doloadb eandefinitions(xmlbeandefinitionreader.java:396)         @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbea ndefinitions(xmlbeandefinitionreader.java:334) [...] 

my properties.xml file looks following. notice have schemalocation correct , line 8 http://www.springframework.org/schema/context

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context"     xmlns:aop="http://www.springframework.org/schema/aop"     xmlns:util="http://www.springframework.org/schema/util"     xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">      <context:property-placeholder         location="classpath:test.properties"  system-properties-mode="override"/>  <!-- -->  </beans> 

looking around other solutions saw people suggested putting classpath of xsd directly beans tag. went ahead , tried this.

<beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"      xmlns:context="http://www.springframework.org/schema/context"     xmlns:util="http://www.springframework.org/schema/util"     xsi:schemalocation="http://www.springframework.org/schema/beans  classpath:/org/springframework/beans/factory/xml/spring-beans-3.2.xsd http://www.springframework.org/schema/context classpath:/org/springframework/context/config/spring-context-3.2.xsd http://www.springframework.org/schema/util  classpath:/org/springframework/beans/factory/xml/spring-util-3.2.xsd"> </beans> 

this solution seemed work beans not context. next solution looked article found while ago stating might related maven overwriting spring.schemas file , not appending file (this solution). realized spring.schemas included mvc schemas looked suggestion of using maven shade build jar (using example). shade allow transformer tell maven append file rather overwrite allowing multiple dependencies use same file.

final pom:

<build>         <plugins>             <plugin>                 <artifactid>maven-compiler-plugin</artifactid>                 <configuration>                     <source>1.7</source>                     <target>1.7</target>                 </configuration>             </plugin>              <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-jar-plugin</artifactid>                 <version>2.4</version>                 <configuration>                     <archive>                         <manifest>                             <addclasspath>true</addclasspath>                             <mainclass>com.mainclass</mainclass>                         </manifest>                     </archive>                     <shadedartifactattached>true</shadedartifactattached>                     <shadedclassifiername>jar-with-dependencies</shadedclassifiername>                     <finalname>filename</finalname>                 </configuration>             </plugin>             <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-shade-plugin</artifactid>                 <version>1.7</version>                 <executions>                     <execution>                         <phase>package</phase>                         <goals>                             <goal>shade</goal>                         </goals>                     </execution>                 </executions>                 <configuration>                     <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>                 </configuration>              </plugin>         </plugins>      </build> 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -