java - java spring 2.0中如何配置jasypt?
问题描述
Jasypt 有问题。我无法使用 Java Spring 在我的程序中配置 jasypt。
这是我在 jdbc.properties 中的配置:
c3p0.db.driverClass = org.postgresql.Driver
c3p0.db.url = jdbc:postgresql://localhost:5432/igate-iacss
c3p0.db.user = postgres
c3p0.db.pass = ENC(5Urp3uiKn828jwkOerTslYtSSeMul0p7)
c3p0.db.initialPoolSize = 5
c3p0.db.minPoolSize = 5
c3p0.db.maxPoolSize = 20
c3p0.num.helper.thread = 5
我在 xml 中的数据源代码:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd"
default-lazy-init="false">
<!-- turn on @Resource, @PostConstruct, and @PreDestroy -->
<context:annotation-config />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>${c3p0.db.driverClass}</value>
</property>
<property name="jdbcUrl">
<value>${c3p0.db.url}</value>
</property>
<property name="user">
<value>${c3p0.db.user}</value>
</property>
<property name="password">
<value>${c3p0.db.pass}</value>
</property>
<property name="initialPoolSize">
<value>${c3p0.db.initialPoolSize}</value>
</property>
<property name="minPoolSize">
<value>${c3p0.db.minPoolSize}</value>
</property>
<property name="maxPoolSize">
<value>${c3p0.db.maxPoolSize}</value>
</property>
<property name="numHelperThreads">
<value>${c3p0.num.helper.thread}</value>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
如何在 java spring 中配置它?请帮我。我希望有人可以帮助我,只是堆叠,不能再思考了。
解决方案
spring 和 jasypt 的集成请参考文档http://www.jasypt.org/spring3.html#取决于您使用的 spring 版本。
我用 jasypt 创建了一个示例 spring 应用程序。如果您正在寻找示例spring-jasypt-example ,请参阅此处的 repo
您可能需要添加 mvn 依赖jasypt-mvn-dependency并集成 jasypt-spring-configuration。