2013-01-13 3 views
0

문제는 applicationContext.xml 내에 구성 요소 검색을 넣을 때 봄을 시작할 수 없지만 dispatcher-servlet.xml에 구성 요소 검색을 넣으면 제대로 작동합니다.SpringContent 스캐너가 applicationContext.xml에서 작동하지 않습니다.

환경 :

봄 3.1.3

의 Web.xml

결국 스프링 부팅하지만이 실패 할 때 617,451,515,
<listener> 
     <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
    </listener> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

<context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/config/applicationContext.xml 
      /WEB-INF/config/shiro-security.xml 
     </param-value> 
</context-param> 
<servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/config/dispatcher-servlet.xml</param-value> 
     </init-param> 
     <load-on-startup>2</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
</servlet-mapping> 

applicationContext.xml

<aop:aspectj-autoproxy proxy-target-class="true"/> 
<context:component-scan base-package="com.keype.hawk" /> 

나는 모든 콩을 볼 수 있습니다

<!-- Annotation driven programming model --> 
    <mvc:annotation-driven> 
     <mvc:message-converters> 
      <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> 
       <property name="objectMapper" ref="customJacksonMapper" /> 
      </bean> 
     </mvc:message-converters> 
    </mvc:annotation-driven> 

디스패처-servlet.xml 파일이 포착되었다. 로그에서 :

INFO :org.springframework.web.context.support.XmlWebApplicationContext[postProcessAfterInitialization]:Bean 'securityManager' of type [class org.apache.shiro.web.mgt.DefaultWebSecurityManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
INFO :org.springframework.web.context.support.XmlWebApplicationContext[postProcessAfterInitialization]:Bean 'authorizationAttributeSourceAdvisor' of type [class org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
INFO :org.springframework.web.context.support.XmlWebApplicationContext[postProcessAfterInitialization]:Bean 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
INFO :org.springframework.web.context.support.XmlWebApplicationContext[postProcessAfterInitialization]:Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
INFO :org.springframework.beans.factory.support.DefaultListableBeanFactory[preInstantiateSingletons]:Pre-instantiating singletons in org.s[email protected]125e8982: defining beans [org.springframework.aop.config.internalAutoProxyCreator,warehouseStockLevelDaoImpl,transactionsDaoImpl,trackingDaoImpl,warehouseTypeDaoImpl,documentTypeDaoImpl,warehouseProductStockDaoImpl,unitDaoImpl,documentItemDaoImpl,pricingTemplateDaoImpl,documentItemSerialNumbersDaoImpl,supplierContractItemDaoImpl,.. [Huge list. Deleting the rest]org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy 
INFO :org.springframework.beans.factory.support.DefaultListableBeanFactory[destroySingletons]:Destroying singletons in org.s[email protected]125e8982: defining beans [org.springframework.aop.config.internalAutoProxyCreator,warehouseStockLevelDaoImpl,transactionsDaoImpl,trackingDaoImpl,warehouseTypeDaoImpl,documentTypeDaoImpl,warehouseProductStockDaoImpl,unitDaoImpl,documentItemDaoImpl,pricingTemplateDaoImpl,documentItemSerialNumbersDaoImpl,supplierContractItemDaoImpl,productSetDaoImpl,productTypeDaoImpl,productDaoImpl,productPriceListDaoImpl,supplierContractDaoImpl,productBrandDaoImpl,productCategoryDaoImpl,warehouseDa [Huge list. Deleting the rest] org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy 
INFO :org.springframework.cache.ehcache.EhCacheManagerFactoryBean[destroy]:Shutting down EHCache CacheManager 
ERROR:org.springframework.web.context.ContextLoader[initWebApplicationContext]:Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'documentItemService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.keype.hawk.inventory.service.InventoryProductService com.keype.hawk.inventory.service.DocumentItemService.inventoryProductService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'inventoryProductService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.keype.hawk.inventory.service.DocumentItemService com.keype.hawk.inventory.service.InventoryProductService.documentItemService; nested exception is java.lang.IllegalArgumentException: Can not set com.keype.hawk.inventory.service.DocumentItemService field com.keype.hawk.inventory.service.InventoryProductService.documentItemService to $Proxy25 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 

봄 [인 preInstantiateSingletons] 다음 그것을 파괴한다. 디버깅을 위해, 나는 디스패처-servlet.xml에

<aop:aspectj-autoproxy proxy-target-class="true"/> 
    <context:component-scan base-package="com.keype.hawk" /> 

문제가 없어 정상적으로 스프링 부팅에 아래 라인을 움직였다. component 스캐너가 applicationContext.xml에있을 때 어떻게 위의 문제를 해결할 수 있습니까?

--update : 컨트롤러가 dispatcher-servlet.xml에 속해야 반면 전체 디버그 로그, applicationContext.xml 및 디스패처-servlet.xml 파일은 here

답변

0

모든 서비스 구성 요소는 applicationContext.xml의 구성 요소 검사의 일부를해야합니다. 동일한 유형의 빈이 두 개 이상있는 것 같습니다. 이 경우 Autowiring은 적합하지 않습니다. 충돌하는 유형의 bean을 명시 적으로 선언하고 xml에서 혼자서 연결하여 충돌을 해결할 수 있습니다. 보십시오 here을보십시오.

+0

좋은 정보와 링크에 대한 감사. 그러나 여기서 인터페이스는 사용하지 않습니다. 나는 클래스를 프록시로 사용하고 복제본을 사용하지 않는다. 또한 디스패처 구성 파일에 코드를 삽입하는 방법은 무엇입니까? 어떤 생각? –

+0

봄은 싱글 톤을 파괴하기 때문에 시작시 로그에 인쇄되지 않는 오류가 발생할 수 있습니다. 잠재적 인 문제를 찾기 위해 디버깅 수준으로 로깅을 만드십시오. 스캔이 dispatcher-servlet.xml에있을 때 아무런 문제가 없는데도 나에게도 당황 스럽다. –

+0

고맙습니다. 확실히 당신의 지시를 따르십시오. 스프링 디버그를 읽는 데 능숙하지 않습니다. 게시하면, 무슨 일이 일어나고 있는지 볼 수 있습니까? –

관련 문제