2012-01-25 24 views
3

Java-EEアプリケーションでSpringとHibernateを使用しています。プロジェクトはthis GitHub repositoryで開催されています。autowired依存関係の注入が失敗しました

package no.niths.rest; 

// Imports ... 

@Controller 
@RequestMapping("courses") 
public class CourseController implements SimpleREST<Course>{ 

    @Autowired 
    public CourseService service; 
} 

そしてrespecticeサービス:

package no.niths.services; 

// Imports ... 

@Service 
public class CourseService { 

    @Autowired 
    public ICourse repo; 
} 

そして最後に、私のapp-config.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <bean id="propertyConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>/configuration.properties</value> 
       </list> 
     </property> 
    </bean> 
    <context:annotation-config /> 
    <context:component-scan base-package="no.niths.services"/> 
    <context:component-scan base-package="no.niths.rest"/> 
    <context:component-scan base-package="no.niths.infrastructure"/> 
    <context:component-scan base-package="no.niths.infrastructure.interfaces"/> 
    <context:component-scan base-package="no.niths.domain"/> 


    <import resource="db-config.xml" /> 
</beans> 

とエラー私が使用して問題を抱えている `このようなサービスを通じて@Autowiredデプロイ時にスローされます。

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'courseController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private no.niths.services.CourseService no.niths.rest.CourseController.service; nested exception is org.springfrainitmework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [no.niths.services.CourseService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    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) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723) 
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226) 
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private no.niths.services.CourseService no.niths.rest.CourseController.service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [no.niths.services.CourseService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284) 
    ... 21 more 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [no.niths.services.CourseService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478) 
    ... 23 more 

ERROR | 2012-01-26 15:30:07,999 | ContextLoader.java | 307 | Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'courseController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private no.niths.services.CourseService no.niths.rest.CourseController.service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [no.niths.services.CourseService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    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) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723) 
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226) 
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private no.niths.services.CourseService no.niths.rest.CourseController.service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [no.niths.services.CourseService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284) 
    ... 21 more 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [no.niths.services.CourseService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478) 

は何これを引き起こしているとどのような問題が、このオートワイヤリング:ここは、更新されたスタックトレースのですか?

+2

エラーが示すように、コードが正しくコンパイルされません。あなたが最初にそれをコンパイルすることができない場合、アプリケーションを展開するポイントはありません。 – skaffman

+0

最初にコードをコンパイルしないのはなぜですか?私はそこでの思考過程を理解しているかどうかはわかりませ – AHungerArtist

+0

@skaffman私は、Eclipseと何らかの継続的な統合機能を使用しているため、Mavenがビルドした後で、EclipseをSpringFabricサーバーにデプロイしようとしています。 – whirlwin

答えて

0

問題は、コントローラか何かではありませんでしたが、いくつかのリポジトリクラスではSessionFactory@Autowiredを使用していました。

+1

"SessionFactory"でも同じ問題がありますが、解決策は何ですか? – vissu

+0

@vissupepala本当に遅く返事を申し訳ありませんが、私は実際にはわかりません。被験者は不幸にも文書化が不十分である。 – whirlwin

0

spring-beans.jarがアプリのクラスパスにあることを確認してください。あなたのプロジェクトがビルド(私は推測WAR)のjarがWEB-INF/libにあることを確認している場合、このjarファイルが依存

  • として含まれているかどうかを確認するために:あなたは「木MVN依存関係」を使用することができ達人で

  • +0

    はい、そこにあります。 – whirlwin

    +0

    WindowsまたはUnixですか? Unixで開いているファイルの最大数の制限を確認する(ulimitコマンド) – maximdim

    +0

    * nix、それは '無制限 'と言います。 – whirlwin

    4

    org.springframework.beans.factory.annotation.Autowired注釈クラスが含まれているのSpring Beanの依存関係を、追加します。

    <dependency> 
        <groupId>org.springframework</groupId> 
        <artifactId>spring-beans</artifactId> 
        <version>3.1.0.RELEASE</version> 
    </dependency> 
    
    +1

    注釈はすでに利用可能であるようですが、既にいくつかの単体テストで使用していますが、良い提案です。 – whirlwin

    +0

    spring-beans JARがWARのWEB-INF/libフォルダにあるかどうか確認してください。 –

    +0

    はい、私はそれを見つけました: 'WEB-INF/lib/spring-beans-3.1.0.RELEASE.jar'。 – whirlwin

    関連する問題