我已经编写了一个spring引导应用程序来监视作业,并连接了客户端的配置属性以调用作业服务中的服务。我在src/test/resources中使用了一个名为application-test.yml的yml文件。在运行测试时,我还将活动配置文件设置为-Dspring.profiles.active=' test‘,spring表示活动配置文件为test。但是,当我运行测试时,配置属性host和path始终为空。下面是我的配置文件:
spring:
profiles: test myservices:客户端:
printservice:
host: app/sms/appdev.com
path: jobs/{jobId}
monitorNgService:
host: app/monitor/appdev.com
path: iqueue/jobs/{jobKey}/servers下面是我的配置类:
@Configuration
@ConfigurationProperties(prefix="myservices.clients")
class PrintServiceProperties{
String host;
String path;
}另一个configuration类加载yml文件中的第二个配置。对于host和path,它也有null。这是该文件;
@Configuration
@ConfigurationProperties(prefix="myservices.clients")
class MonitorNgServiceProperties{
String host;
String path;
}我将这个类注入到一个使用这些属性的类中,但这些属性为空
这是类
@Service
@Import(MonitorNgServiceProperties)
@Slf4j
class MonitorService implements InitializingBean{
@Autowired
MonitorNgServiceProperties monitorNgService我在这上面花了几个小时,但不明白为什么属性不能加载。如果您能帮助我解决这个问题,我将非常感激
发布于 2019-06-02 09:34:21
问题是我漏掉了最后一个前缀:
@ConfigurationProperties(prefix="myservices.clients.printservice")https://stackoverflow.com/questions/56411456
复制相似问题