Announcement Announcement Module
Collapse
No announcement yet.
Issue with spring context loader detecting spring-security-web package on classpath Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with spring context loader detecting spring-security-web package on classpath

    Hi all,

    This is my first post in the spring forums so howdy!

    I'm sure you've been asked this question a million times before but I'm experiencing the following error message when I attempt to load the application context with spring and use a very basic spring security example. Please bear in mind this is my first attempt to get spring authentication working:-

    Code:
     [junit] java.lang.IllegalStateException: Failed to load ApplicationContext
        [junit] 	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
      ...
        [junit] Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [test-security.xml]
        [junit] Offending resource: class path resource [spring-test-context.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: spring-security-web classes are not available. You need these to use <filter-chain-map>
        [junit] Offending resource: class path resource [test-security.xml]
        [junit] 	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    The ant target trying to run the unit tests contains the following:-
    Code:
    	<target name="unit-test" depends="unit-test-compile">
    		<junit printsummary="false" haltonfailure="true">
    			<classpath>
    				<path refid="build.classpath"/>
    				<path refid="test.classpath"/>
    				<path refid="resources.classpath"/>
    				<path refid="test.resources.classpath"/>
    			</classpath>
    			<formatter type="brief" usefile="false"/>
    			<formatter type="xml" />
    			<batchtest todir="${test.data.dir}">
    				<fileset dir="${build.out.test.dir}">
    					<include name="**/*Test.class"/>
    				</fileset>
    			</batchtest>
    		</junit>
    	</target>
    The paths contain the following jar packages at runtime:-
    Code:
    build.classpath = :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/ant-web-tasks-1.0.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/antlr-2.7.6.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/asm-attrs.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/asm.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/cglib-2.2.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/commons-collections-3.1.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/commons-dbcp-all-1.3.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/commons-logging-1.1.1.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/dom4j-1.6.1.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/ehcache-1.2.3.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/ejb3-persistence-1.0.2.GA.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/hibernate-testing.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/hibernate3.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/javassist-3.12.0.GA.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/jta-1.1.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/jta.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/junit.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/liquibase.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/log4j-1.2.15.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/mockito-all-1.8.5.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/mysql-connector-java-5.1.15-bin.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.hamcrest.core_1.1.0.v20090501071000.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.aop-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.asm-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.aspects-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.beans-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.context-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.context.support-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.core-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.expression-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.instrument-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.instrument.tomcat-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.jdbc-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.jms-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.orm-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.oxm-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.test-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.transaction-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.web-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.web.portlet-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.web.servlet-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/org.springframework.web.struts-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/slf4j-api-1.6.1.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-acl-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-aspects-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-cas-client-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-config-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-core-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-ldap-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-openid-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-taglibs-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/WebContent/WEB-INF/lib/spring-security-web-3.0.5.RELEASE.jar
    :/Users/jamurphy84/Documents/Projects/java/teambox/build/out/classes
    
    test.classpath = /Users/jamurphy84/Documents/Projects/java/teambox/build/out/classes/test
    resources.classpath = /Users/jamurphy84/Documents/Projects/java/teambox/build/out/main/resources
    test.resources.classpath = /Users/jamurphy84/Documents/Projects/java/teambox/build/out/test/resources
    The contents of my test-spring-security.xml is:-

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
      	xmlns:security="http://www.springframework.org/schema/security"
      	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-3.0.xsd
              http://www.springframework.org/schema/security
              http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
    	 
    	 <security:http auto-config='true'>
    	 	<security:intercept-url pattern="/**" access="ROLE_USER"/>
    	 	<security:form-login login-page='/login.jsp'/>
    	 </security:http>
    	
    	<security:authentication-manager>
    		<security:authentication-provider>
    			<security:user-service>
    				<security:user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" />
    	            <security:user name="player1" password="player1" authorities="ROLE_USER" />
    	            <security:user name="player2" password="player2" authorities="ROLE_USER" />
    	            <security:user name="player3" password="player3" authorities="ROLE_USER" />	
    			</security:user-service>
    		</security:authentication-provider>
    	</security:authentication-manager>
    </beans>
    Anyone have any ideas? I'm concerned I might have overloaded the path with lots of jars I don't need. To be honest it's probably frustration because I thought this should be working already. I thought the only classes I would need are core, config and web as a bare minimum am I wrong?

    I'm using spring 3.0.5 and spring security 3.0.5 which I would assume should play okay together.

    Any help is much appreciated.

  • #2
    Noone knows the answer?

    I've been stuck on this for a couple of days now (before i posted here).

    I can't believe it's this difficult to set up spring security and get it working - very much contemplating just implementing my own solution or getting a 3rd party working. Some people have said that they're using Maven to pull in dependencies.

    It shouldn't be this hard to get it all set up with ant though right?!?

    Comment


    • #3
      Solved

      Nevermind,

      I've resolved the problem by just using Maven to build my project instead. Took me the best part of a day to convert the project over to Maven but really it shouldn't be that difficult in ant.

      I think the errors that Spring Security gave wrt class loading issues was ambiguous. It could find the spring-web packages it just couldn't find the transitive dependencies I think.

      Anyway feel free to close it - message me anyone if you want help getting spring security started - with Maven at least!

      Comment


      • #4
        I agree, it's typically not that hard to get basic Spr Sec working. Had you noticed any other errors earlier in the chain? Sometimes classloader errors are the result of other dependencies not being present (this seems also indicative of the fact that things started working when you put Maven in the mix). The only obvious missing dependency is aopalliance.jar. However, now that you have it all working with Maven, you're probably in better shape anyway with regards to dependency management. Best of luck in your future work with the framework!

        Comment


        • #5
          Thanks for responding - that was pretty much the whole error I could see. You're probably right about aopalliance I probably just missed that. It's really hard to tell without more specific errors.

          I haven't gotten maven working completeiy with it just yet. It's nearly there but at least making much more progress. I'll post more if I have any further problems.

          Thanks.

          Comment

          Working...
          X