Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 3自动连线注释不工作_Spring_Annotations_Autowired - Fatal编程技术网

Spring 3自动连线注释不工作

Spring 3自动连线注释不工作,spring,annotations,autowired,Spring,Annotations,Autowired,我在使自动连线批注正常工作时遇到了一些问题。请看这两个类: @Component("upAuthenticationProvider") public class UPAuthenticationProvider implements AuthenticationProvider { @Autowired private AuthenticationDAO authenticationDAO; // snip public AuthenticationDAO

我在使自动连线批注正常工作时遇到了一些问题。请看这两个类:

@Component("upAuthenticationProvider")
public class UPAuthenticationProvider implements AuthenticationProvider {

    @Autowired
    private AuthenticationDAO authenticationDAO;

    // snip

    public AuthenticationDAO getAuthenticationDAO() {
    return authenticationDAO;
    }

    public void setAuthenticationDAO(
          AuthenticationDAO authenticationDAO) {
    this.authenticationDAO = authenticationDAO;
    }
}
以及依赖性:

@Repository
public class AuthenticationPostgresDAO implements AuthenticationDAO{

    @Autowired
    private DataSource dataSource;

    // snip...
}
我在应用程序初始化时的日志中看到:

08:09:41.268 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'upAuthenticationProvider'
08:09:41.268 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'upAuthenticationProvider'
08:09:41.269 [pool-2-thread-1] DEBUG o.s.b.f.annotation.InjectionMetadata - Found injected element on class [com.mycompany.authentication.UPAuthenticationProvider]: AutowiredFieldElement for private com.mycompany.dao.AuthenticationDAO com.mycompany.authentication.UPAuthenticationProvider.AuthenticationDAO
08:09:41.269 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'upAuthenticationProvider' to allow for resolving potential circular references
08:09:41.271 [pool-2-thread-1] DEBUG o.s.b.f.annotation.InjectionMetadata - Processing injected method of bean 'upAuthenticationProvider': AutowiredFieldElement for private com.mycompany.dao.AuthenticationDAO com.mycompnay.authentication.UPAuthenticationProvider.AuthenticationDAO
08:09:41.273 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'AuthenticationPostgresDAO'
08:09:41.273 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'AuthenticationPostgresDAO'
08:09:41.273 [pool-2-thread-1] DEBUG o.s.b.f.annotation.InjectionMetadata - Found injected element on class [com.mycompnay.dao.AuthenticationPostgresDAO]: AutowiredFieldElement for private javax.sql.DataSource com.mycompany.dao.AuthenticationPostgresDAO.dataSource
08:09:41.273 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'authenticationPostgresDAO' to allow for resolving potential circular references
08:09:41.273 [pool-2-thread-1] DEBUG o.s.b.f.annotation.InjectionMetadata - Processing injected method of bean 'authenticationPostgresDAO': AutowiredFieldElement for private javax.sql.DataSource com.mycompnay.dao.AuthenticationPostgresDAO.dataSource
08:09:41.274 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'dataSource'
08:09:41.274 [pool-2-thread-1] DEBUG o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - Autowiring by type from bean name 'AuthenticationPostgresDAO' to bean named 'dataSource'
08:09:41.274 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'authenticationPostgresDAO'
08:09:41.274 [pool-2-thread-1] DEBUG o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - Autowiring by type from bean name 'upAuthenticationProvider' to bean named 'authenticationPostgresDAO'
08:09:41.274 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'upAuthenticationProvider'
08:09:41.274 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'authenticationPostgresDAO'

它似乎在告诉我它创建了依赖项并将其连接起来,但在我的应用程序中,当我尝试从upAuthenticationProvider访问authencticationPostgresDAO时,我得到了一个NPE,因此问题显然不在您向我们展示的代码中。。。 1) 如何访问upAuthenticationProvider实例,您应该从Spring应用程序上下文获取它。
2) 抛出NPE的代码是什么?抛出异常的行上是否有非DAO的内容为null?

您的applicationContext.xml文件中是否有:和?@BenSchro10是的,我已将它们都设置好。我正在使用spring安全命名空间向身份验证管理器提供upAuthenticationProvider,例如:[code][code]抱歉-按enter键,然后无法编辑。这里是我想要键入的内容:我使用spring安全名称空间向身份验证管理器提供upAuthenticationProvider:
我也使用
表单登录
,因此我假设所有正常活动都在执行该方法。NPE发生在使用
authenticationDAO
的一行上,但这是一个很好的观点。我在那一行设置了一个断点,类成员
authenticationDAO
在该点为null。