2017-04-24 13 views
0

Ich verwende CGLib (AOP) -Proxy. Gibt es eine Problemumgehung, wenn ComboPooledDataSource die letzte Klasse ist, da @RefreshScope in der letzten Klasse nicht funktioniert?Spring @RefreshScope funktioniert nicht in der endgültigen Klasse ComboPooledDataSource

Die letzte Klasse ComboPooledDataSource ist Teil des c3p0-Verbindungspools.

<!-- Hibernate c3p0 connection pool --> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-c3p0</artifactId> 
    <version>5.0.4.Final</version> 
</dependency> 

Antwort

0

Schritt 1: Erstellen Sie eine Klasse 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(); 
    } 

} 

Schritt 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); 
} 
genannt
Verwandte Themen