Я создал Службу и загружаю ее с помощью @Service ("amazonService").
Мой контекст приложения загружает этот сервис, используя
Я настраиваю свойства используя
<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>
В моем сервисе Amazon я делаю:
public class AmazonServiceImpl implements FileStorageService {
private AmazonS3 amazonClient;
@Value("${abcxyz}")
public String bucketName ;
И мой файл props имеет свойство abcxyz = my-bucket
Но это плохо работает со следующим исключением:
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?