Announcement Announcement Module
Collapse
No announcement yet.
Context initialization failed with Spring3.0.4 Security using JDBC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Context initialization failed with Spring3.0.4 Security using JDBC

    Hi,

    we are going to implement Spring Security for our existing Struts1.3+Hibernate3.2+Spring3 application.
    Step by Step we are injecting spring into our existing application.
    But we are getting the below exception at the time of application deployment in Tomcat7. For complete error log please refer the attached document.

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name

    'org.springframework.security.provisioning.JdbcUse rDetailsManager#0': Cannot resolve reference to bean 'dataSource' while

    setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No

    bean named 'dataSource' is defined
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference

    (BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary

    (BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues

    (AbstractAutowireCapableBeanFactory.java:1325)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean

    (AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean

    (AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean

    (AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton

    (DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference

    (BeanDefinitionValueResolver.java:322)
    ... 51 more
    Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'dataSource' is defined
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition

    (DefaultListableBeanFactory.java:527)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedLocalBeanDefinition

    (AbstractBeanFactory.java:1068)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:274 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference

    (BeanDefinitionValueResolver.java:322)
    Our main Spring context file(applicationContext.xml) is having all bean definitions, including "datasource" bean definition also.
    The applicationContext.xml content :
    HTML Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:security="http://www.springframework.org/schema/security"
      xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
    
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
           http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
    
    	
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource" scope="singleton">
    		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
    		<property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"></property>
    		<property name="username" value="bunny"></property>
    		<property name="password" value="jessy"></property>
    	</bean>
    
    <!-- contains rest of the beans -->
    Below file contains all the information about security configuration
    spring-security.xml

    HTML Code:
    <beans:beans xmlns="http://www.springframework.org/schema/security"
    	xmlns:beans="http://www.springframework.org/schema/beans" 
    	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">
     
    	<http auto-config="true">
    		<intercept-url pattern="/common*" access="ROLE_USER" />
    		<form-login login-page="/login" default-target-url="/commontrpage.do"
    			authentication-failure-url="/loginfailed" />
    		<logout logout-success-url="/logout" />
    	</http>
    	
    	
     
    	<authentication-manager>
    	   <authentication-provider>
    		<jdbc-user-service data-source-ref="dataSource"
     
    		   users-by-username-query="
    		      select username,password, enabled 
    		      from users where username=?" 
     
    		   authorities-by-username-query="
    		      select u.username, ur.authority from users u, user_roles ur 
    		      where u.user_id = ur.user_id and u.username =?  " 
     
    		/>
    	   </authentication-provider>
    	</authentication-manager>
     
    </beans:beans>
    our web.xml file which included above files

    web.xml:

    HTML Code:
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">
    
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/applicationContext.xml</param-value>
    		<param-value>/WEB-INF/spring-security.xml</param-value>
    	</context-param>
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
    
    	<servlet>
    		<servlet-name>context</servlet-name>
    		<servlet-class>
    			org.springframework.web.context.ContextLoaderServlet
    	  </servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<!-- Spring Security -->
    	<filter>
    		<filter-name>springSecurityFilterChain</filter-name>
    		<filter-class>
    			org.springframework.web.filter.DelegatingFilterProxy
                    </filter-class>
    	</filter>
    
    	<filter-mapping>
    		<filter-name>springSecurityFilterChain</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    also please observe our project jar files

    ant-antlr-1.6.3.jar
    antlr-2.7.5H3.jar
    aopalliance.jar
    asm-3.0.jar
    asm-attrs.jar
    cglib-2.1.jar
    commons-beanutils.jar
    commons-collections-2.1.1.jar
    commons-dbcp.jar
    commons-digester.jar
    commons-lang.jar
    commons-lang-2.0.jar
    commons-logging-1.0.4.jar
    commons-pool.jar
    commons-validator.jar
    dom4j-1.6.jar
    ehcache-1.1.jar
    hibernate-3.2.jar
    hsqldb.jar
    jstl-1.2.jar
    jta.jar
    log4j-1.2.8.jar
    ojdbc14.jar
    org.springframework.transaction-3.0.4.RELEASE.jar
    spring-aop-3.0.4.RELEASE.jar
    spring-asm-3.0.4.RELEASE.jar
    spring-beans-3.0.4.RELEASE.jar
    spring-context-3.0.4.RELEASE.jar
    spring-core-3.0.4.RELEASE.jar
    spring-expression-3.0.4.RELEASE.jar
    spring-jdbc-3.0.4.RELEASE.jar
    spring-orm-3.0.4.RELEASE.jar
    spring-security-config-3.0.4.RELEASE.jar
    spring-security-core-3.0.4.RELEASE.jar
    spring-security-taglibs-3.0.4.RELEASE.jar
    spring-security-web-3.0.4.RELEASE.jar
    spring-struts-3.0.4.RELEASE.jar
    spring-web-3.0.4.RELEASE.jar
    spring-webmvc-3.0.4.RELEASE.jar
    standard.jar
    struts.jar
    strutsspringhibernate.jar
    xerces-2.6.2.jar
    Please help us as we are in urgent.

  • #2
    Hi Friends, Please help us with this issue.

    Comment


    • #3
      I don't see anything immediately wrong. Can you post your full debug logs? Are you certain your applicationContext.xml with the DataSource is getting loaded (i.e. it is in WEB-INF)? What happens if you define the DataSource in the spring-security.xml

      Comment


      • #4
        Hi Rob Winch,

        Thanks for your response. We managed to execute our app by updating schemas for the below configuration files.

        applicationContext.xml file

        <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:security="http://www.springframework.org/schema/security"
        xmlns="http://www.springframework.org/schema/p"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"

        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
        spring-security.xml file
        <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:security="http://www.springframework.org/schema/security"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schem...-beans-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.4.xsd">

        <!-- Loads main context configurations -->
        <import resource="applicationContext.xml" />

        <security:http auto-config="true">
        <security:intercept-url pattern="/common*" access="ROLE_USER" />
        <security:form-login login-page="/login" default-target-url="/commontrpage.do"
        authentication-failure-url="/loginfailed" />
        <security:logout logout-success-url="/logout" />
        </security:http>

        <security:authentication-manager>
        <security:authentication-provider>
        <security:jdbc-user-service data-source-ref="myDataSource"

        Comment

        Working...
        X