Tag: hocon

由Typesafe配置支持的Spring环境

我想在我的项目中使用typesafe配置(HOCON配置文件),这有助于简化和组织应用程序配置。 目前我正在使用普通的Java属性文件(application.properties),这在大项目中很难处理。 我的项目是Spring MVC(不是Spring启动项目)。 有没有办法支持我的Spring环境(我将注入到我的服务中)以支持typesafe配置。 这不应该像@Value注释,@ @Autowired Environment等那样制止我现有的环境使用。 如何以最小的努力和我的代码更改来完成此操作。 这是我目前的解决方案:寻找还有其他更好的方法 @Configuration public class PropertyLoader{ private static Logger logger = LoggerFactory.getLogger(PropertyLoader.class); @Bean @Autowired public static PropertySourcesPlaceholderConfigurer properties(Environment env) { PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); Config conf = ConfigFactory.load(); conf.resolve(); TypesafePropertySource propertySource = new TypesafePropertySource(“hoconSource”, conf); ConfigurableEnvironment environment = (StandardEnvironment)env; MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addLast(propertySource); pspc.setPropertySources(propertySources); return […]