开发者

Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace

My setup is fairly simple: I have a web front-end, back-end is spring-wired.

I am using AOP to add a layer of security on my rpc services.

It's all good, except for the fact that the web app aborts on launch:

  [java] SEVERE: Context initialization failed
     [java] org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/aop]
     [java] Offending resource: ServletContext resource [/WEB-INF/gwthandler-servlet.xml]

Here is the snippet from my xml config file:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    <aop:config>
        <aop:aspect id="security" ref="securityAspect" >
            <aop:pointcut id="securedServices" expression="@annotation(com.fb.boog.common.aspects.Secured)"/>
            <aop:before method="checkSecurity" pointcut-ref="securedServices"/>
        </aop:aspect>
    </aop:config>

I read over the internets that it may be my classloading the core of the problem. Doubtful, since here is my WEB-INF/lib directory:

./WEB-INF/lib
./WEB-INF/lib/aopalliance-alpha1.jar
./WEB-INF/lib/aspectj-1.6.6.jar
./WEB-INF/lib/commons-collections.jar
./WEB-INF/lib/commons-logging.jar
./WEB-INF/lib/ehcache-core-1.7.0.jar
./WEB-INF/lib/ejb3-persistence.jar
./WEB-INF/lib/hibernate
./WEB-INF/lib/hibernate/antlr.jar
./WEB-INF/lib/hibernate/asm.jar
./WEB-INF/lib/hibernate/bsh-2.0b1.jar
./WEB-INF/lib/hibernate/cglib.jar
./WEB-INF/lib/hibernate/dom4j.jar
./WEB-INF/lib/hibernate/freemarker.jar
./WEB-INF/lib/hibernate/hibernate-annotations.jar
./WEB-INF/lib/hibernate/hibernate-shards.jar
./WEB-INF/lib/hibernate/hibernate-tools.jar
./WEB-INF/lib/hibernate/hibernate.jar
./WEB-INF/lib/hibernate/jtidy-r8-20060801.jar
./WEB-INF/lib/jabsorb
./WEB-INF/lib/jabsorb/jabsorb-1.3.1.jar
./WEB-INF/lib/jta.jar
./WEB-INF/lib/jyaml-1.3.jar
./WEB-INF/lib/postgresql-8.4-701.jdbc4.jar
./WEB-INF/lib/sjsxp.jar
./WEB-INF/lib/spring
./WEB-INF/lib/spring/org.springframework.aop-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.asm-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.aspects-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.beans-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.context-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.context.s开发者_StackOverflowupport-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.core-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.expression-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.instrument-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.instrument.tomcat-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.jdbc-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.jms-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.orm-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.oxm-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.test-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.transaction-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.web-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.web.portlet-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.web.servlet-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.web.struts-3.0.0.RELEASE.jar
./WEB-INF/lib/testng-5.11-jdk15.jar
./WEB-INF/web.xml


Encountered this error while using maven-shade-plugin, the solution was including:

META-INF/spring.schemas

and

META-INF/spring.handlers

transformers in the maven-shade-plugin when building...

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <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>
            </execution>
        </executions>
    </plugin>

(Credits: Idea to avoid that spring.handlers/spring.schemas get overwritten when merging multiple spring dependencies in a single jar)


http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html

I ran into a similar problem using the maven-shade-plugin. I found the solution to my problems in their example page above.


What IDE (if any) are you using? Does this happen when you're working within an IDE, or only on deployment? If it's deployment, it might be because whatever mechanism of deployment you use -- maven-assembly making a single JAR with dependencies is a known culprit -- is collapsing all your JARs into a single directory and the Spring schema and handler files are overwriting each other.


Did you try putting all your jars directly in the WEB-INF/lib dir instead of sub-dirs of that?

No WEB-INF/lib/spring/org.springframework.aop-3.0.0.RELEASE.jar, just WEB-INF/lib/org.springframework.aop-3.0.0.RELEASE.jar

Same with the rest of the jars.


I ran into a similar error, but refering to Spring Webflow in a newly created Roo project. The solution for me turned out to be (Project) / right-click / Maven / Enable Maven Dependencies (followed by some restarts and republishes to Tomcat).

It appeared that STS or m2Eclipse was failing to push all the spring webflow jars into the web app lib directory. I'm not sure why. But enabling maven dependency handling and then rebuilding seemed to fix the problem; the webflow jars finally get published and thus it can find the schema namespace references.

I investigated this by exploring the tomcat directory that the web app was published to, clicking into WEB-INF/lib/ while it was running and noticing that it was missing webflow jar files.


This trick worked for me too: In Eclipse right-click on the project and then Maven > Update Dependencies.


In case someone else runs into this problem, I just did using Eclipse; running the project via the right click action. This error occurred in the J2EE view, but did NOT occur in the Java view. Not sure - assuming something with adding libraries to the correct 'lib' directory.

I am also using a Maven project, allowing m2eclipse to manage dependancies.


I have the same problem with spring 3.0.2 and spring-beans-3.0.xsd.

My solution:

Create a file META-INF/spring.schemas in the source folder and copy all necesary definitions. Create spring.handlers too.

I think that the class PluggableSchemaResolver is not working correctly.

http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/xml/PluggableSchemaResolver.html

from the javadoc:

"By default, this class will look for mapping files in the classpath using the pattern: META-INF/spring.schemas allowing for multiple files to exist on the classpath at any one time."

but in my case, this class only read the first spring.schemas finded.

Grettings. pacovr


If using mvn, check that you have the correct scope (if you have that defined) in your pom.xml. I once had it incorrectly set to test but needed it for runtime.


Make sure you have all dependencies solved

I run into this problem in my first attempt at AOP, following a spring tutorial. My problem was not having spring-aop.jar in my classpath. The tutorial listed all other dependencies I had to add, namely:

  • aspectjrt.jar
  • aspectjweaver.jar
  • aspectj.jar
  • aopalliance.jar

But the one was missing. Just one more problem that can contribute to that symptom in the original question.

I am using Eclipse (neon), Java SE 8, beans 3.0, spring AOP 3.0, Spring 4.3.4. The problem showed in the Java view --not JEE--, and while trying to just run the application with Right button menu -> Run As -> Java Application.


You can also try using the one-jar maven plugin which fixed the problem for us. Simply follow the instructions from here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜