Spring @RefreshScope 对最终 class ComboPooledDataSource 不起作用
Spring @RefreshScope does not work on final class ComboPooledDataSource
我正在使用 CGLib (AOP) 代理。当 ComboPooledDataSource 是 final class 时是否有任何解决方法,因为 @RefreshScope 在 final class 上不起作用?
@Bean(name = "portalDataSource", destroyMethod = "close")
@RefreshScope
public DataSource dataSource() Integer iMaxConTimeout) throws Exception {
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.mysql.jdbc.Driver"); //loads the jdbc driver
cpds.setJdbcUrl("....");
cpds.setUser("...");
cpds.setPassword("...");
// the settings below are optional -- c3p0 can work with defaults
cpds.setMinPoolSize(iMinDBCons);
cpds.setMaxPoolSize(iMaxDBCons);
cpds.setMaxIdleTime(iMaxConTimeout);
return cpds;
}
最后的 class ComboPooledDataSource 是 c3p0 连接池的一部分。
<!-- Hibernate c3p0 connection pool -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.0.4.Final</version>
</dependency>
第 1 步:创建一个 class 名为 SigComboPooledDataSource
public class SigComboPooledDataSource extends TransactionAwareDataSourceProxy {
@Autowired
// Inject your class by constructor
SigComboPooledDataSource(ComboPooledDataSource dataSource) {
super.setTargetDataSource(dataSource);
}
public void close() {
((ComboPooledDataSource) super.getTargetDataSource()).close();
}
}
步骤 2
@Bean(name = "portalDataSource", destroyMethod = "close")
@RefreshScope
public DataSource dataSource() Integer iMaxConTimeout) throws Exception {
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.mysql.jdbc.Driver"); //loads the jdbc driver
cpds.setJdbcUrl("....");
cpds.setUser("...");
cpds.setPassword("...");
cpds.setPassword("...");
// the settings below are optional -- c3p0 can work with defaults
cpds.setMinPoolSize(iMinDBCons);
cpds.setMaxPoolSize(iMaxDBCons);
cpds.setMaxIdleTime(iMaxConTimeout);
return new SigComboPooledDataSource(cpds);
}
我正在使用 CGLib (AOP) 代理。当 ComboPooledDataSource 是 final class 时是否有任何解决方法,因为 @RefreshScope 在 final class 上不起作用?
@Bean(name = "portalDataSource", destroyMethod = "close")
@RefreshScope
public DataSource dataSource() Integer iMaxConTimeout) throws Exception {
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.mysql.jdbc.Driver"); //loads the jdbc driver
cpds.setJdbcUrl("....");
cpds.setUser("...");
cpds.setPassword("...");
// the settings below are optional -- c3p0 can work with defaults
cpds.setMinPoolSize(iMinDBCons);
cpds.setMaxPoolSize(iMaxDBCons);
cpds.setMaxIdleTime(iMaxConTimeout);
return cpds;
}
最后的 class ComboPooledDataSource 是 c3p0 连接池的一部分。
<!-- Hibernate c3p0 connection pool -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.0.4.Final</version>
</dependency>
第 1 步:创建一个 class 名为 SigComboPooledDataSource
public class SigComboPooledDataSource extends TransactionAwareDataSourceProxy {
@Autowired
// Inject your class by constructor
SigComboPooledDataSource(ComboPooledDataSource dataSource) {
super.setTargetDataSource(dataSource);
}
public void close() {
((ComboPooledDataSource) super.getTargetDataSource()).close();
}
}
步骤 2
@Bean(name = "portalDataSource", destroyMethod = "close")
@RefreshScope
public DataSource dataSource() Integer iMaxConTimeout) throws Exception {
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.mysql.jdbc.Driver"); //loads the jdbc driver
cpds.setJdbcUrl("....");
cpds.setUser("...");
cpds.setPassword("...");
cpds.setPassword("...");
// the settings below are optional -- c3p0 can work with defaults
cpds.setMinPoolSize(iMinDBCons);
cpds.setMaxPoolSize(iMaxDBCons);
cpds.setMaxIdleTime(iMaxConTimeout);
return new SigComboPooledDataSource(cpds);
}