2012-05-25 6 views
0

Autowired 주석을 작동하는 데 문제가 있습니다. 응용 프로그램 초기화 할 때 내가 로그에서 볼봄 3 Autowired 주석이 작동하지 않습니다.

@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' 

것 같습니다

@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; 
    } 
} 

및 종속성 :이 두 클래스를 참조하십시오 종속성 및 유선 있지만 내 응용 프로그램에서 upAuthenticationProvider authencticationPostgresDAO 액세스하려고 할 때 NPE 얻을

+0

applicationContext.xml 파일에 가 있습니까? – BenSchro10

+0

@ BenSchro10 예, 둘 다 설정했습니다. –

답변

0

그래서 문제는 분명히 우리에게 보여주는 코드가 아닙니다 ... 1) upAuthenticationProvider의 인스턴스에 어떻게 접근합니까? Spring ApplicationContext에서 가져와야합니다. 2) NPE를 던지는 코드는 무엇입니까? DAO 이외의 뭔가가 예외를 throw하는 줄에 null이 될 수 있습니까?

+0

나는 스프링 보안 네임 스페이스를 사용하여 upAuthenticationProvider를 인증 관리자에게 다음과 같이 제공합니다. [코드] <인증 관리자> <인증 공급자 참조 = "upAuthenticationProvider"/> [코드] –

+0

죄송합니다 - 입력하고 편집 할 수 없습니다. 을 나는 같은 인증 관리자에 upAuthenticationProvider을 공급하는 봄 보안 네임 스페이스를 사용하고 있습니다 : 여기 입력 무엇을 의미 '<인증 관리자> <인증 업체 심판 = "upAuthenticationProvider"/> ' 'form-login'도 사용하고 있습니다. 따라서 모든 정상적인 활동이 메소드를 실행한다고 가정합니다. NPE는 'authenticationDAO'를 사용하는 라인에서 발생하지만, 좋은 지적입니다. 그 줄에 중단 점을 설정하면 클래스 구성원 'authenticationDAO'는 그 시점에서 null입니다. –

관련 문제