我在配置SSL相关env时遇到问题。我的SpringBoot应用程序中的属性。以下是属性
server.ssl.key-store=XXXX
server.ssl.key-password=XXXX
server.ssl.trust-store=XXXX
ActiveMQ使用以上属性来保护连接。以下是示例代码
@Bean
public ActiveMQConnectionFactory connectionFactory(){
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(this.brokerUrl);
connectionFactory.setUseAsyncSend(this.useAsyncSend);
connectionFactory.setAlwaysSessionAsync(this.alwaysSessionAsync);
connectionFactory.setOptimizeAcknowledge(this.optimizeAcknowledge);
connectionFactory.setUserName(this.Username);
connectionFactory.setPassword(this.password);
return connectionFactory;
}
但是上面的代码无法创建SSL连接,而是以与ActiveMQ的TCP连接结束。所以我稍微改变代码来调试问题
@Bean
public ActiveMQConnectionFactory connectionFactory(){
System.setProperty("javax.net.ssl.keyStore", "broker.ks");
System.setProperty("javax.net.ssl.keyStorePassword", "XXXXX");
System.setProperty("javax.net.ssl.trustStore", "client.ts");
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(this.brokerUrl);
connectionFactory.setUseAsyncSend(this.useAsyncSend);
connectionFactory.setAlwaysSessionAsync(this.alwaysSessionAsync);
connectionFactory.setOptimizeAcknowledge(this.optimizeAcknowledge);
connectionFactory.setUserName(this.Username);
connectionFactory.setPassword(this.password);
return connectionFactory;
}
然后它开始正常工作。它能够在客户端和服务器之间建立SSL连接。所以我得出结论,application.properties文件中包含的属性是在@Configuarion类加载后加载的。 所以我的查询是“是否可以在DispatchcherServlet开始加载所有配置类之前加载这些与env相关的属性?”