有谁知道我是否应该使用属性占位符作为限定符中的表达式?我似乎无法让这个工作.
我使用的是Spring 3.0.4.
@Controller
public class MyController {
@Autowired
@Qualifier("${service.class}")
Service service;
}
@Service
@Qualifier("ServiceA")
ServiceA implements Service {
public void print() {
System.out.println("printing ServiceA.print()");
}
}
@Service
@Qualifier("ServiceB")
ServiceB implements Service {
public void print() {
System.out.println("printing ServiceB.print()");
}
}
Run Code Online (Sandbox Code Playgroud)
XML:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:/etc/config.properties"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
config.properties:
config.properties
service.class=serviceB
Run Code Online (Sandbox Code Playgroud) 如何在 Spring Boot 中使用 Java 配置为 bean 定义之外的 bean 取别名?