我有以下控制器定义:用SpringMVC:变量在注释
@Controller
@RequestMapping("/test")
public class MyController extends AbstractController
{
@Autowired
public MyController(@Qualifier("anotherController") AnotherController anotherController))
{
...
}
}
我不知道是否有可能在@Qualifier注解使用变量,这样我可以注入不同的.properties文件不同的控制器如:
@Controller
@RequestMapping("/test")
public class MyController extends AbstractController
{
@Autowired
public MyController(@Qualifier("${awesomeController}") AnotherController anotherController))
{
...
}
}
每当我尝试,我得到:
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type [com.example.MyController] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this
dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Qualifier(value=${awesomeController})
我已经包括d我的config.xml文件下面bean:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/application.properties</value>
</list>
</property>
</bean>
但豆不起作用,除非我在XML文件中显式声明的bean。
我该怎么做注释?
http://stackoverflow.com/questions/317687/how-can-i-inject-a-property-value-into-a-spring-bean-which-was-configured-using和http:// springinpractice 。COM/2008/12/02 /新的东西,在弹簧-30/ – NimChimpsky 2013-04-04 16:02:00