【发布时间】:2017-07-31 11:23:31
【问题描述】:
我的应用程序只是启动一个 ActiveMQ 代理。
我想在 Spring Boot 中使用基于 XML 的配置,以利用 ActiveMQ 代理的 XML 配置(引用 here)。
我正在使用 jasypt-spring-boot-starter 来满足我的加密需求,但似乎在初始化 XML 配置时我的密码的加密值没有被解密。
启动过程中没有错误。只是当我尝试使用 admin/user 访问代理时,它会失败并出现错误“用户名 [用户] 或密码无效。”
主 Spring Boot 应用类
@Configuration
@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication
@RestController
@ImportResource({"classpath:activemq.xml"})
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
摘自 Broker Config (activemq.xml)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="${activemq.broker.name}" dataDirectory="${activemq.broker.data}">
<plugins>
<runtimeConfigurationPlugin checkPeriod="1000" />
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="admin" password="${activemq.broker.admin.password}" groups="users,admins" />
<authenticationUser username="user" password="${activemq.broker.user.password}" groups="users" />
<authenticationUser username="guest" password="${activemq.broker.guest.password}" groups="guests" />
</users>
</simpleAuthenticationPlugin>
</plugins>
...more
application.properties
jasypt.encryptor.password=thisisnotapassword
jasypt.encryptor.algorithm=PBEWITHMD5ANDTRIPLEDES
activemq.broker.admin.password=ENC(OZRghRNXYpRiiw18KD7P6Uf2Y7fOieI7)
activemq.broker.user.password=ENC(yOiHeJlh6Z+VRVmSZe//Yw==)
activemq.broker.guest.password=guest
我从启动日志中注意到的一件事是 activemq.xml 在 jasypt 相关日志出现之前被加载
Loading XML bean definitions from class path resource [activemq.xml]
...some logs
String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor
【问题讨论】:
-
为什么要在 Spring Boot 中使用 xml 配置?
-
如前所述,这是为了利用 ActiveMQ 代理的 XML 配置。除了配置(xml/properties)外,无需修改应用程序。
-
问题在于您使用 XML 支持命名空间。占位符的实际解析现在是通过命名空间完成的,而不是常规的 Spring 机制。因此,它将在 Spring Boot 更改解码属性之前被调用。
-
有没有办法不使用命名空间支持?
-
@acys 你有解决办法吗?
标签: java xml spring encryption jasypt