属性文件只使用1-bean

时间:2017-12-18 00:16:47

标签: spring-boot

我正在使用Spring启动。 引导配置包含在application.yml

这是我的情况。

接口CommonService

类AServiceImpl.java + a-config.properties class BServiceImpl.java + b-config.properties ...

@PropertiesSource(value="${b.config.file.name})
@Service("bService")
public class BServiceImpl implements CommonService{
     ...
}

属性文件包含相同的属性,差值。

我希望在自己的服务中使用属性。 而不是getter类型(不是getProperty)。

我可以吗?

1 个答案:

答案 0 :(得分:0)

I think you should use only one property then @Autowired Environment and you can use this.getClass().getSimpleName() for dynamic prefix property name

application.yml

BServiceImpl : yourchild : yourvalue 

AService

@Service("aService")
public class AServiceImpl implements CommonService{
     @Autowired
     Environment env;

}

BService

@Service("bService")
public class BServiceImpl implements CommonService{
     @Autowired
     Environment env;

}

How to a getProperty

env.getProperty(this.getClass().getSimpleName()+"yourchild");