0

我的 java 配置文件如下所示 -

@Bean
public JdbcTemplate jdbcTemplate() {
    JdbcTemplate template = new JdbcTemplate(dataSource());
    return template;
}

@Bean
public DataSource dataSource() {
    JndiDataSourceLookup dataSource = new JndiDataSourceLookup();
    return dataSource.getDataSource(env.getProperty("spring.datasource"));
}

我的属性文件属性如下所示 -

spring.datasource.username=<myusername>
spring.datasource.password=<mypassword>
spring.datasource.url=jdbc:oracle:thin:@<url>
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.initSQL=select 1 from dual
spring.datasource.maxActive=50
spring.datasource.minIdle=20
spring.datasource.maxIdle=50
spring.datasource.defaultAutoCommit=true
spring.datasource.initialSize=20
spring.datasource.maxWait=300000
spring.datasource.validationQuery=select 1 from dual
spring.datasource.testOnBorrow=true
spring.datasource.testWhileIdle=false
spring.datasource.timeBetweenEvictionRunsMillis=-1
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true

在我自动装配 JdbcTemplate 的地方,在其中一种方法中,我尝试打印 jdbcTemplate.getDataSource() 并打印以下内容 -

org.apache.tomcat.jdbc.pool.DataSource@659c54d2{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=oracle.jdbc.driver.OracleDriver; maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=************; url=jdbc:oracle:thin:@<url>; username=<myusername>; validationQuery=SELECT 'Hello' from DUAL; validationQueryTimeout=-1; validatorClassName=null; validationInterval=30000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; }

除了用户名、密码和 URL 之外,它基本上没有采用我设置的任何配置。这是为什么?

4

0 回答 0