Hello guys, i was following this tutorial http://stackoverflow.com/questions/2...with-hibernate, and I'm stuck on this error
userDetailsServiceCode:2011-03-12 23:42:43,131 [main] ERROR (ContextLoader.java:220) ? Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.config.authentication.AuthenticationManagerFactoryBean] while setting bean property 'parent'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailsService' is defined
apllicationContext-security.xmlCode:package cz.xkadle21.dip.service.impl; ... /** * * * @author CVnek * */ @Service("userDetailsService") public class DiUserContextSecurityService implements UserDetailsService, IDiUserContextSecurityService { @Autowired private IDiUsersDAO usersDao; @Autowired private IDiSecurityUserFactory securityUserFactory; public DiUserContextSecurityService() { super(); } // @Autowired // public DiUserContextSecurityService(IDiUsersDAO usersDAO, // IDiSecurityUserFactory securityUserFactory) { // super(); // this.usersDao = usersDAO; // this.securityUserFactory = securityUserFactory; // } public Authentication getCurrentUser() { return SecurityContextHolder.getContext().getAuthentication(); } @Transactional(readOnly = true) public User loadUserByUsername(String username) { DiUser user = usersDao.findUserByUsername(username); UserDetails userDetails = null; if (user != null) { throw new UsernameNotFoundException("user not found"); } return securityUserFactory.buildSecurityUserFromEntity(user); } }
spring-servlet.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <b:beans xmlns="http://www.springframework.org/schema/security" xmlns:b="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.xsd"> <http use-expressions="true"> <intercept-url pattern="/" access="permitAll" /> <intercept-url pattern="/admin/**" access="isAuthenticated()" /> <intercept-url pattern="/js/**" filters="none" /> <intercept-url pattern="/css/**" filters="none" /> <intercept-url pattern="/images/**" filters="none" /> <form-login /> <logout /> </http> <security:authentication-manager> <security:authentication-provider user-service-ref="userDetailsService" /> </security:authentication-manager> </b:beans>
When i put into apllicationCiontext-security.xmlCode:<?xml version="1.0" encoding="UTF-8"?> ... only 10 000 Chars :-) <context:annotation-config /> <context:component-scan base-package="cz.xkadle21.dip.controller" /> <context:component-scan base-package="cz.xkadle21.dip.controller.impl" /> <context:component-scan base-package="cz.xkadle21.dip.dao" /> <context:component-scan base-package="cz.xkadle21.dip.dao.impl" /> <context:component-scan base-package="cz.xkadle21.dip.service" /> <context:component-scan base-package="cz.xkadle21.dip.service.impl" /> <context:component-scan base-package="cz.xkadle21.dip.validator" /> <context:component-scan base-package="cz.xkadle21.dip.validation.impl" /> <context:component-scan base-package="cz.xkadle21.dip.factory" /> <context:component-scan base-package="cz.xkadle21.dip.factory.impl" /> <!-- <bean name="userDetailsService" id="userDetailsService" --> <!-- class="cz.xkadle21.dip.service.impl.DiUserContextSecurityService">--> <!-- </bean>--> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass"> <value> org.springframework.web.servlet.view.tiles2.TilesView </value> </property> </bean> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/tiles.xml</value> </list> </property> </bean> <!-- ************ interceptors ************ --> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:interceptors-ref="menuInterceptor" /> <bean id="menuInterceptor" class="cz.xkadle21.dip.interceptor.DiMenuInterceptor" /> <!-- ************************************** --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- ************ properties ************ --> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="classpath:messages" /> <property name="defaultEncoding" value="UTF-8" /> <!-- ************************************ --> </bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.properties" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${hibernate.connection.driver_class}" p:url="${hibernate.connection.url}" p:username="${hibernate.connection.username}" p:password="${hibernate.connection.password}" /> <!-- ************** libraries, js, css ************** --> <mvc:default-servlet-handler /> <mvc:resources mapping="/css/**" location="/css/" /> <mvc:resources mapping="/images/**" location="/images/" /> <mvc:resources mapping="/js/**" location="/js/" /> <!-- ************************************************ --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.show_sql">true</prop> <!-- <prop key="hibernate.hbm2ddl.auto">update</prop>--> </props> </property> </bean> <tx:jta-transaction-manager /> <tx:annotation-driven /> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> </beans>
Code:<b:bean name="userDetailsService" class="cz.xkadle21.dip.service.impl.DiUserContextSecurityService"> </b:bean>
its working elsewhere "normally", but i got NullPointerIxception on usersDao, when I'am calling loadUserByUsername function. Fields are not injected.
or with
than i got NullPointer on sessionFactory ...Code:<b:bean name="userDetailsService" class="cz.xkadle21.dip.service.impl.DiUserContextSecurityService" > <b:constructor-arg ref="userDAO" /> <b:constructor-arg ref="securityUserFactory" /> </b:bean> <b:bean id="userDAO" class="cz.xkadle21.dip.dao.impl.DiUserDAO"/> <b:bean id="securityUserFactory" class="cz.xkadle21.dip.factory.impl.DiSecurityUserFactory"/>
Some russian guy have exactly same problem http://pda.javatalks.ru/sutra103362....9a10ae38ed fd
, but component scan i have.
In advance thank for help. I'am working on this issue almost all day.


Reply With Quote
