我有這樣的例外的SessionFactory的正確注射春春安全
java.lang.NullPointerException
cz.xkadle21.dip.dao.ADiHibernateGenericDAO.findByCriteria(ADiHibernateGenericDAO.java:116)
cz.xkadle21.dip.dao.impl.DiUserDAO.findUserByUsername(DiUserDAO.java:86)
cz.xkadle21.dip.service.impl.DiUserContextSecurityService.loadUserByUsername(DiUserContextSecurityService.java:47)
cz.xkadle21.dip.service.impl.DiUserContextSecurityService.loadUserByUsername(DiUserContextSecurityService.java:1)
我下面這個教程Spring Security 3 database authentication with Hibernate
,並得到了「沒有名叫豆...定義」的錯誤。讓我感動的調度員servlet.xml中豆類的applicationContext-共business.xml和改變裝載在web.xml
的web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-common-business.xml
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
豆在調度員-servlet.xml中與組件加載-scan,並正在自動注入sessionFactory。但是bean在applicationContext-common-business.xml中沒有。
的applicationContext-共business.xml
<bean name="userDetailsService"
class="cz.xkadle21.dip.service.impl.DiUserContextSecurityService" >
<constructor-arg ref="userDAO" />
<constructor-arg ref="securityUserFactory" />
</bean>
<bean id="securityUserFactory" class="cz.xkadle21.dip.factory.impl.DiSecurityUserFactory" />
<bean id="userDAO" class="cz.xkadle21.dip.dao.impl.DiUserDAO" />
<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}" />
<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>
的UserDetailsService通過構造函數注入,但如何注入SessionFactory來userDAO的? SessionFactory在ADiHibernateGenericDAO中定義,並且所有DAO擴展抽象ADiHibernateGenericDAO。上面的異常在SessionFactory上引發,而不是注入。
感謝您的回覆。
嗨,我已經明白了。我認爲這個定義應該只在一個配置文件中。所以我把它放在兩邊,現在它正在工作。 – rizler 2011-03-14 19:23:57
在 -servlet.xml –
2011-03-14 19:53:47
中,當它只存在於 -servlet.xml中時,它比通過applicationContext-common-business加載的不在bean中工作的事務更好。 xml配置文件 –
rizler
2011-03-14 23:00:13