Spring 3.0:无法找到Spring NamespaceHandler for XML schema namespace

2022-09-01 04:14:35

我的设置相当简单:我有一个Web前端,后端是弹簧连接的。

我正在使用AOP在我的rpc服务上添加一层安全。

一切都很好,除了Web应用程序在启动时中止的事实:

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

以下是我的 xml 配置文件中的代码段:

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

我通过互联网阅读,这可能是我的类加载问题的核心。值得怀疑,因为这是我的WEB-INF/lib目录:

./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.support-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

答案 1

在使用maven-shade-plugin时遇到此错误,解决方案包括:

META-INF/spring.schemas

META-INF/spring.handlers

变压器在maven-shade-plugin中构建...

    <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:避免spring.handlers/spring.schemas在单个jar中合并多个spring依赖项时被覆盖的想法)


答案 2

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

我在使用maven-shade-plugin时遇到了类似的问题。我在上面的示例页面中找到了解决问题的方法。


推荐