Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @Spring MVC 3.0.6中的值失败_Java_Spring Mvc_Annotations - Fatal编程技术网

Java @Spring MVC 3.0.6中的值失败

Java @Spring MVC 3.0.6中的值失败,java,spring-mvc,annotations,Java,Spring Mvc,Annotations,我已经创建了一个服务,并使用@Service(“amazonService”)加载它。 我的应用程序上下文正在使用加载此服务 我正在使用配置属性 <bean id="propsHolder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreResourceNotFound" value="true" />

我已经创建了一个服务,并使用@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>
我的道具文件有一个属性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?

这很奇怪。即使以某种方式未加载属性,
@Value
注释也应解析为括号内的字符串

因此,请尝试升级到3.1(最近发布),或降级到3.0.5(我相信这是可行的)。还要确保没有更改xml中的默认自动连接策略。

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

相反



请确保确实加载了Spring配置文件:在其中添加一些语法错误,如果应用程序像以前一样运行,那么问题是该文件未按预期使用。

确保在与控制器相同的应用程序上下文中声明PropertyPlaceholderConfigurer bean。BeanFactory后处理器(如PPC)不会跨父/子应用程序上下文边界继承。可能您的PPC是在“根”应用程序上下文中声明的,但您的组件扫描指令是在子(DispatcherServlet)上下文中声明的。这不起作用,将呈现您报告的结果。

我知道了!实际上,应用程序已经在web.xml中将其自定义XMLWebapplication上下文配置为其spring上下文加载程序侦听器


这不是将调用传递给超级方法,超级方法实际上负责注册@Value注释处理器。

Wierd问题是,我不知道它是否正在尝试自动连接@Valueplaceholder@hellojava:请检查应用程序(请参见我答案中的提示)
<context:property-placeholder location="classpath:/applicationConfig.properties"/>