我目前正在使用带有 Struts2-spring 插件的 Struts2 创建 Web 应用程序。
这是我的 applicationContext.xml 的片段
<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。我们甚至提供了 setter 和 getter,  authenticateLoginService但是正如您所看到的,当我们运行返回 null 的
authenticate(Authentication auth)方法时,authenticationLoginService我们不知道为什么会发生这种情况。请注意 AccountAuthenticationManager 不是 Struts Action
我们目前正在使用 struts2-spring 插件和 spring security。