在非SpringBoot应用程序中加载application.properties文件

时间:2018-06-08 09:35:05

标签: spring spring-boot

我使用spring boot并使用feign作为客户端构建了一组微服务。一切都很完美,但我的非SpringBoot应用程序有问题。

在这种情况下,我想使用配置属性文件(application.properties)来配置不同的客户端(如Ribbon)。 在我的配置bean中,我已经为所有组件包含了@ImportAutoConfiguration,但是没有从属性文件加载配置。

有没有办法执行此操作?

谢谢!

1 个答案:

答案 0 :(得分:0)

import org.springframework.context.annotation.PropertySource;
@RequestMapping("/url")
@Controller
@PropertySource("classpath:config.properties")
public class StudentController{
  @Autowired
  private Environment env;

  //get properties using keys
  //env.getProperty("key");

}

并将config.properties文件放在src/main/resources

相关问题