tags:

views:

6259

answers:

7

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"&gt;
    <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.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  A: 

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.

delfuego
Using IntelliJ for an IDE. No problems in the IDE, everything checks out. I am using ant to assemble the web app, and the listing above is from the war directory.
Nick Hristov
+1 to delfuego for linking to MASSEMBLY-360; that's exactly the problem I'm having.
Andrew Swan
If using Spring 2.5.6, you can work around this by using the all-in-one "spring" JAR file that comes with that version (as opposed to separately using spring-core, spring-beans, spring-jdbc, etc.)
Andrew Swan
+3  A: 

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.

Peter Lynch
Yep -- according to this, subdirectories under `WEB-INF/lib` aren't valid. Never knew one way or another how that'd work... nice to know now. http://code.google.com/appengine/docs/java/tools/ant.html#Copying_JARs
delfuego
By the way, I suspect that the reason it works fine in IntelliJ is that IntelliJ is using a custom classloader...
delfuego
Yes, that fixed it. IntelliJ does not complain , because it has the jars added in directly under the libraries section.
Nick Hristov
A: 

Not related to your problem but you might be better off using the versioned names of the xsd files:

<beans: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:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;
Lumpy Oatmeal
A: 

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.

wuntee
A: 

I have a similar problem... I am using spring 2.5.6, including all-in-one jar does not solve the problem... My offending resource is type [jar:file:gvSIG/extensiones/prueba-ext/lib/basesig-model-db-utils-1.0-SNAPSHOT.jar!/config/application-context.xml] (inside a jar)

David
A: 

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/sprin...aResolver.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

Francisco Villa Ramos
+1  A: 

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.

Kevin