2014-01-24 4 views
19

문제가있는 곳을 알려주십시오. 여기 내 프로젝트입니다 : https://github.com/intrade/inventory 내가 자바 설정을 사용하여 봄 보안을 사용하려고 내가 my SecurityConfig class에 입력 MyCustomUserDetailsService의 종속성을 주입하려고 할 때 예외 얻을 :스프링 보안의 UserDetails에 @Autowired 반환 예외가 발생했습니다

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.springapp.mvc.services.MyCustomUserDetailsService com.springapp.mvc.InitApp.SecurityConfig.myCustomUserDetailsService; nested exception is java.lang.IllegalArgumentException: Can not set com.springapp.mvc.services.MyCustomUserDetailsService field com.springapp.mvc.InitApp.SecurityConfig.myCustomUserDetailsService to com.sun.proxy.$Proxy38 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) 
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1551) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) 
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) 
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:622) 
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:569) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) 
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) 
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487) 
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97) 
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328) 
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420) 
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) 
    at sun.rmi.transport.Transport$1.run(Transport.java:177) 
    at sun.rmi.transport.Transport$1.run(Transport.java:174) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173) 
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.springapp.mvc.services.MyCustomUserDetailsService com.springapp.mvc.InitApp.SecurityConfig.myCustomUserDetailsService; nested exception is java.lang.IllegalArgumentException: Can not set com.springapp.mvc.services.MyCustomUserDetailsService field com.springapp.mvc.InitApp.SecurityConfig.myCustomUserDetailsService to com.sun.proxy.$Proxy38 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) 
    ... 56 more 
Caused by: java.lang.IllegalArgumentException: Can not set com.springapp.mvc.services.MyCustomUserDetailsService field com.springapp.mvc.InitApp.SecurityConfig.myCustomUserDetailsService to com.sun.proxy.$Proxy38 
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164) 
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168) 
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) 
    at java.lang.reflect.Field.set(Field.java:741) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:510) 
    ... 58 more 

Jan 24, 2014 1:18:32 PM org.apache.catalina.core.ApplicationContext log 

사전에 감사를!

답변

53

클래스별로 사용자 세부 정보 서비스를 자동 연결하려고하지만 실제로 작동하지 않습니다. 스프링 빈은 실제로 클래스의 인스턴스가 아니라 해당 클래스 주위에 생성 된 프록시이기 때문입니다. 그러나 프록시는 원래 빈의 모든 인터페이스를 구현하므로 인터페이스로 주입하는 것이 안전합니다.

교환이 라인이 하나

@Autowired 
private MyCustomUserDetailsService myCustomUserDetailsService; 

:

@Autowired 
private UserDetailsService myCustomUserDetailsService; 

가 세부 사항을 이해하기 위해 스프링 AOP에 Proxying Mechanisms 섹션을 읽어보십시오.

+0

감사합니다. 한 번 더 문제를 일으킬 수 있습니까? 새로운 예외가 발생했습니다 : org.springframework.beans.factory.BeanCreationException : 클래스 경로 resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]에 'springSecurityFilterChain' 빈 인스턴스화에 실패했습니다. 중첩 예외는 org.springframework.beans.factory.BeanDefinitionStoreException입니다 : 팩토리 메소드 [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() –

+1

@AleksandrsRudzitis 더 필요합니다. info (전체 스택 추적). 새로운 질문을하거나 직접 저에게 연락하십시오 (내 프로필 페이지 참조) –

+0

다음은 스택 추적의 전체 게시물입니다 : http://stackoverflow.com/questions/21335182/springsecurityfilterchain-nullpointer-exception –

관련 문제