Tag: 配置

Spring @PostConstruct取决于@Profile

我想在一个配置类中有多个@PostConstruct注释的方法,这应该被称为依赖于@Profile。 你可以想象一个代码如下所示: @Configuration public class SilentaConfiguration { private static final Logger LOG = LoggerFactory.getLogger(SilentaConfiguration.class); @Autowired private Environment env; @PostConstruct @Profile("test") public void logImportantInfomationForTest() { LOG.info("********** logImportantInfomationForTest"); } @PostConstruct @Profile("development") public void logImportantInfomationForDevelopment() { LOG.info("********** logImportantInfomationForDevelopment"); } } 但是根据@PostConstruct的javadoc,我只能使用这个注释来注释一个方法。 在Spring的Jira https://jira.spring.io/browse/SPR-12433中有一个改进。 你如何解决这个要求? 我总是可以将这个配置类分成多个类,但也许你有一个更好的主意/解决方案。 BTW。 上面的代码运行没有问题,但是无论配置文件设置如何,都会调用这两个方法。

通过JSON配置选择策略

我正在Java / Kotlin中实施一个学习代理。 该代理功能的一部分涉及通过大量可能的选项进行搜索。 搜索可能性空间有很多好方法,我经常改变我的想法,哪一个是最好的。 所以我决定把它作为一个战略模式来实施。 class Agent(val searchStrategy : SearchStrategy){ fun search(input : InputGraph) : Result{ return searchStrategy.search() } } interface SearchStrategy{ fun search(input : InputGraph) : Result } class FastSearch : SearchStrategy{ //implementation here } class AccurateSearch : SearchStrategy{ // implementation here } class ExperimentalSerach : SearchStrategy{ // implentation here } 最近,我决定运行一大组实验来测试各种系统参数的有效性。 这是通过一个python脚本完成的,该脚本通过运行带有不同config.json文件的编译jar作为参数来踢每个实验。 […]

Kotlin spring-boot @ConfigurationProperties

我正在尝试创建以下bean AmazonDynamoDBAsyncClientProvider 。 我有application.properties定义endpoint和tablePrefix ,我试图注入使用@ConfigurationProperties 以下是相同的代码片段。 当我运行我的春季启动应用程序不起作用。 我已经尝试使用一个普通的java类来做相同的ConfigurationProperties类,它不会设置这些属性,但是当涉及到AmazonDynamoDBAsyncClientProvider ,属性是空的。 我在这里错过了什么? @Component open class AmazonDynamoDBAsyncClientProvider @Autowired constructor(val dynamoDBConfiguration: DynamoDBConfig){ @Bean open fun getAmazonDBAsync() = AmazonDynamoDBAsyncClientBuilder.standard() .withEndpointConfiguration( AwsClientBuilder.EndpointConfiguration(dynamoDBConfiguration.endpoint, dynamoDBConfiguration.prefix)) .build() } 这里是我试图用配置自动装配的kotlin bean @Component @ConfigurationProperties(value = "dynamo") open class DynamoDBConfig(var endpoint: String="", var prefix: String="") 最后继承了常规的java bean,它使用ConfigurationProperties填充,但是当它获得Autowired时,我看到这些属性为空/ null @Component @ConfigurationProperties("dynamo") public class DynamoDBConfiguration { private String endpoint; […]