【发布时间】:2013-01-17 14:05:45
【问题描述】:
我目前正在使用带有 Struts2-spring 插件的 Struts2 创建 Web 应用程序。
这是我的 applicationContext.xml 的 sn-p
<bean id="sessionFactory" scope="singleton"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<!-- Springs Hibernate Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven />
<!-- Create DAO Objects -->
<bean id = "userDao" class = "org.hitplay.users.dao.UserDao" scope = "singleton">
<property name ="sessionFactory" ref = "sessionFactory" />
</bean>
<bean id = "adminDao" class = "org.hitplay.admin.dao.AdminDao" scope = "singleton">
<property name ="sessionFactory" ref = "sessionFactory" />
</bean>
<bean id="authenticateLoginService" class="org.hitplay.services.AuthenticateLoginService" scope="singleton">
<property name="userDao" ref="userDao" />
<property name="adminDao" ref="adminDao" />
</bean>
<bean id="accountAuthenticationManager" class="org.hitplay.authentication.manager.AccountAuthenticationManager" scope="singleton">
<property name="authenticateLoginService" ref="authenticateLoginService" />
</bean>
这是我的 AccountAuthenticationManager 类
@Transactional
public class AccountAuthenticationManager implements AuthenticationManager {
protected static Logger logger = Logger.getLogger("service");
// Our custom DAO layer
private AuthenticateLoginService authenticateLoginService;
public AuthenticateLoginService getAuthenticateLoginService() {
return authenticateLoginService;
}
public void setAuthenticateLoginService(
AuthenticateLoginService authenticateLoginService) {
this.authenticateLoginService = authenticateLoginService;
}
public Authentication authenticate(Authentication auth) throws AuthenticationException {
System.out.println(authenticateLoginService);
//Some more codes here
}
正如您在我们的映射中看到的,我们将authenticateLoginService 注入到AccountAuthenticationManager 类中。我们甚至为authenticateLoginService 提供了setter 和getter,但是当我们运行authenticate(Authentication auth) 方法时,您可以看到authenticationLoginService 返回null,我们不知道为什么会这样。请注意,AccountAuthenticationManager 不是 Struts Action
我们目前正在使用 struts2-spring 插件和 spring security。
【问题讨论】:
-
我认为我们需要使用
-
如何获取AccountAuthenticationManager的引用?您是否通过 Spring Injection 获得 AccountAuthenticationManager 的实例?或者你只是使用“新”键来创建一个?我在你的配置文件中看不到任何问题,如果它未能查找/注入依赖项,spring 会在启动时警告你。由于您没有提到 Spring 抛出的任何异常,我想知道您如何获取 AccountAuthenticationManager 的实例。
-
@spiritwalker 我让 spring AccountAuthenticationManager 通过 spring 注入本身创建。我用这个弹簧安全。但是
-
您是否面临仅使用 authenticateLoginService 或其他对象的问题
-
仅使用 authenticateLoginService
标签: spring spring-security dependency-injection struts2 struts2-spring-plugin