markdown springboot中的Oracle UCP配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown springboot中的Oracle UCP配置相关的知识,希望对你有一定的参考价值。
Config class
```
@Configuration
@ConditionalOnClass(oracle.ucp.UniversalConnectionPool.class)
@EnableConfigurationProperties(UCPDataSourceProperties.class)
public class OracleConfig {
@Autowired
private UCPDataSourceProperties ucpProps;
@Bean
@Primary
public DataSource ucpDataSource() throws SQLException {
System.out.println(ucpProps);
PoolDataSource poolDataSource = PoolDataSourceFactory.getPoolDataSource();
poolDataSource.setURL(ucpProps.getUrl());
poolDataSource.setUser(ucpProps.getUser());
poolDataSource.setPassword(ucpProps.getPassword());
poolDataSource.setConnectionFactoryClassName(ucpProps.getConnectionFactoryClassName());
poolDataSource.setConnectionWaitTimeout(ucpProps.getConnectionWaitTimeout());
poolDataSource.setInactiveConnectionTimeout(ucpProps.getInactiveConnectionTimeout());
poolDataSource.setInitialPoolSize(ucpProps.getInitialPoolSize());
poolDataSource.setMinPoolSize(ucpProps.getMinPoolSize());
poolDataSource.setMaxPoolSize(ucpProps.getMaxPoolSize());
poolDataSource.setConnectionProperty("v$session.program", "DBCON");
poolDataSource.setValidateConnectionOnBorrow(ucpProps.getValidateConnectionOnBorrow());
return poolDataSource;
}
}
```
Property class
```
public class UCPDataSourceProperties {
private String url;
private String user;
private String password;
private String connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource";
private int connectionWaitTimeout=1000;
private int inactiveConnectionTimeout=30000;
private int initialPoolSize=1;
private int minPoolSize=1;
private int maxPoolSize=10;
private Boolean validateConnectionOnBorrow=true;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getConnectionFactoryClassName() {
return connectionFactoryClassName;
}
public void setConnectionFactoryClassName(String connectionFactoryClassName) {
this.connectionFactoryClassName = connectionFactoryClassName;
}
public int getConnectionWaitTimeout() {
return connectionWaitTimeout;
}
public void setConnectionWaitTimeout(int connectionWaitTimeout) {
this.connectionWaitTimeout = connectionWaitTimeout;
}
public int getInactiveConnectionTimeout() {
return inactiveConnectionTimeout;
}
public void setInactiveConnectionTimeout(int inactiveConnectionTimeout) {
this.inactiveConnectionTimeout = inactiveConnectionTimeout;
}
public int getInitialPoolSize() {
return initialPoolSize;
}
public void setInitialPoolSize(int initialPoolSize) {
this.initialPoolSize = initialPoolSize;
}
public int getMinPoolSize() {
return minPoolSize;
}
public void setMinPoolSize(int minPoolSize) {
this.minPoolSize = minPoolSize;
}
public int getMaxPoolSize() {
return maxPoolSize;
}
public void setMaxPoolSize(int maxPoolSize) {
this.maxPoolSize = maxPoolSize;
}
public Boolean getValidateConnectionOnBorrow() {
return true;
}
public void setValidateConnectionOnBorrow(Boolean validateConnectionOnBorrow) {
this.validateConnectionOnBorrow = validateConnectionOnBorrow;
}
@Override
public String toString() {
return "UCPDataSourceProperties{" +
"url='" + url + '\'' +
", user='" + user + '\'' +
", password='" + password + '\'' +
", connectionFactoryClassName='" + connectionFactoryClassName + '\'' +
", connectionWaitTimeout=" + connectionWaitTimeout +
", inactiveConnectionTimeout=" + inactiveConnectionTimeout +
", initialPoolSize=" + initialPoolSize +
", minPoolSize=" + minPoolSize +
", maxPoolSize=" + maxPoolSize +
", validateConnectionOnBorrow=" + validateConnectionOnBorrow +
'}';
}
}
```
Config file
```
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.type=oracle.ucp.jdbc.PoolDataSourceImpl
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
datasource.ucp.connectionFactoryClassName=oracle.jdbc.pool.OracleDataSource
datasource.ucp.url=jdbc:oracle:thin:@//localhost:1521/XE
datasource.ucp.user=youruser
datasource.ucp.password=yourpasswd
datasource.ucp.maxPoolSize=10
datasource.ucp.minPoolSize=2
datasource.ucp.initialPoolSize=2
datasource.ucp.connection-wait-timeout=1000
datasource.ucp.inactive-connection-timeout=30000
datasource.validateConnectionOnBorrow=true
```
以上是关于markdown springboot中的Oracle UCP配置的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot整合Markdown实现图片上传和图片再次回显(详细步骤)
SpringBoot整合Markdown实现图片上传和图片再次回显(详细步骤)