相关疑难解决方法(0)

Spring限定符和属性占位符

有谁知道我是否应该使用属性占位符作为限定符中的表达式?我似乎无法让这个工作.

我使用的是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)

java spring dependency-injection

24
推荐指数
3
解决办法
2万
查看次数

标签 统计

dependency-injection ×1

java ×1

spring ×1