如果将 ${druid.password} 更改为我的数据库密码,一切都很好
如果德鲁伊不解码密码?
我的 db.properties
druid.Driver=com.mysql.cj.jdbc.Driver
druid.url=jdbc:mysql://localhost:3306/dongnanceshi?useSSL=false&useUncode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
druid.user=root
druid.password=fF4CHVVYbY4Q9iHXqaylbdMP9TrlroIq0Bh3cKldca9CX5J7QhKIoXTZ4Ar0JNkVx+GIqYhGvS4gHjA43yq2YQ==
druid.publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAI2z3FiKNWaIlynCGoe+SFOjG2Xd10QP6MNFCF3VcXG8PCLd/xRkkMx9ojfPMdXn8YhcbK79OcpPCkMnlhr2ux0CAwEAAQ==
spring-dao.xml
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${druid.Driver}"/>
<property name="url" value="${druid.url}" />
<property name="username" value="${druid.user}"/>
<property name="password" value="${druid.password}"/>
<property name="filters" value="stat" />
<property name="connectionProperties" value="config.decrypt=true;config.decrypt.key=${druid.publickey}"/>
</bean>
Junit 测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/spring-dao.xml","classpath:spring/spring-service.xml"})
public class TestID {
@Autowired
TEnvBusSiteAirHourdatainfectMapper tEnvBusSiteAirHourdatainfectMapper;
@Test
public void test3() {
List<TEnvBusSiteAirHourdatainfect> tEnvBusSiteAirHourdatainfects = tEnvBusSiteAirHourdatainfectMapper.queryAll("a34002");
}
}
和错误日志
[Druid-ConnectionPool-Create-1912172027] ERROR com.alibaba.druid.pool.DruidDataSource - create connection SQLException, url: jdbc:mysql://localhost:3306/dongnanceshi?useSSL=false&useUncode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai, errorCode 1045, state 28000 java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)