2012-02-19 13 views
0

サービスを作成し、@Service( "amazonService")を使用してロードしています。 私のアプリケーションコンテキストは、私は私が私のアマゾンのサービスでは@ValueがSpring MVC 3.0.6で失敗する

<bean id="propsHolder" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="ignoreResourceNotFound" value="true" /> 
    <property name="locations"> 
     <list> 
      <value>classpath:/applicationConfig.properties</value> 

     </list> 
    </property> 

</bean> 

を使用してプロパティを設定しています を使用してこのサービスをロードしている:

public class AmazonServiceImpl implements FileStorageService { 

    private AmazonS3 amazonClient; 
    @Value("${abcxyz}") 
    public String bucketName ; 

そして、私の小道具ファイルは=私のバケット

プロパティABCXYZを持っています

しかし、これには、以下の例外を除いてひどく失敗:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public java.lang.String com.flipswap.service.impl.AmazonServiceImpl.bucketName; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Value(value=${abczyz})} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) 
    ... 50 more 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Value(value=${abczyz})} 
    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:480) 
    ... 52 more 


Everyone is able to do this successfully and even i succeeded it in a plain java sample. But running in MVC fails. 

Any idea? 
+0

奇妙なことは、私はそれは文脈で3.0 – hellojava

答えて

0

私はそれを手に入れました!実際には、アプリケーションはweb.xmlのカスタムXMLWebApplicationコンテキストをSpringのコンテキストローダリスナとして設定していました。

これは、実際に@Valueアノテーションプロセッサの登録を担当していたスーパーメソッドの呼び出しでは渡されませんでした。

0

これは奇妙です。たとえプロパティが何らかの形でロードされていなくても、@Value注釈は角カッコ内の文字列に解決されるはずです。

3.1にアップグレードする(最近リリースされた)か、3.0.5にダウングレードしてください。また、XMLでデフォルトのautowiring戦略を変更していないことを確認してください。代わりに

+0

をautowireしようとしているのyを知らないということです:プロパティも – Ralph

0

<context:property-placeholder location="classpath:/applicationConfig.properties"/> 


はSpring構成ファイルが実際にロードされていることを確認してください:アプリケーションは前のように実行した場合、それにいくつかの構文エラーを追加し、その後、問題が予想されるように、ファイルが使用されていないということです。

+0

でさえ運を働いてはならない@valueプレースホルダ – hellojava

+0

@hellojava:私にヒントを参照してください(すべてのアプリケーションを確認してください回答) – Ralph

0

PropertyPlaceholderConfigurer Beanが、コントローラと同じアプリケーションコンテキストで宣言されていることを確認してください。 PPCなどのBeanFactoryPostProcessorsは、親/子アプリケーションコンテキストの境界を越えて継承されません。あなたのPPCはあなたの 'root'アプリケーションコンテキストで宣言されているかもしれませんが、あなたのコンポーネントスキャン指示は子(ディスパッチャーサーブレット)コンテキストで宣言されているかもしれません。これはうまくいかず、報告した結果が表示されます。

関連する問題