jboss-jndi-oracle ゝ一世哀愁。 2022-05-17 04:10 125阅读 0赞 # 项目配置 # ## application.yml ## #数据源配置 spring: datasource: # type: com.alibaba.druid.pool.DruidDataSource # driver-class-name: oracle.jdbc.driver.OracleDriver # url: jdbc:oracle:thin:@ip:端口:helowin # username: 用户名 # password: 密码 name: java:/jdbc/pricing http: multipart: maxFileSize: 100Mb maxRequestSize: 100Mb druid: # 初始化大小,最小,最大 initialSize: 50 minIdle: 50 maxActive: 80 # 配置获取连接等待超时的时间 maxWait: 600000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 'x' testWhileIdle: true testOnBorrow: true testOnReturn: false # 打开PSCache,并且指定每个连接上PSCache的大小 poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 filters: stat,wall,log4j # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=50000 profiles: active: dev mvc: locale: zh_CN locale-resolver: fixed aop: proxy-target-class: true # 线程池的配置文件 threads: pool: queueCapacity: 50 corePoolSize: 5 maxPoolSize: 25 keepAliveSeconds: 600 略。。。 ## DruidDataSourceConfiguration ## import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.WebStatFilter; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup; import javax.sql.DataSource; /** * @author wangc wangchuan@shanshu.ai * @date 2018/06/28 */ @Configuration @ConditionalOnClass(com.alibaba.druid.pool.DruidDataSource.class) @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "com.alibaba.druid.pool.DruidDataSource", matchIfMissing = true) public class DruidDataSourceConfiguration { /** * jndi 数据源,德邦生产环境配置 */ @Value("${spring.datasource.name}") private String jndiDataSourceName; @SuppressWarnings("unchecked") protected <T> T createDataSource(DataSourceProperties properties, Class<? extends DataSource> type) { return (T) properties.initializeDataSourceBuilder().type(type).build(); } /** * @param properties 读入的配置 * @return DruidDataSource * @see org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.Tomcat 仿写的你可以去了解 */ @Bean @ConfigurationProperties("spring.datasource.druid") public DataSource dataSource(DataSourceProperties properties) { // com.alibaba.druid.pool.DruidDataSource dataSource = createDataSource(properties, // com.alibaba.druid.pool.DruidDataSource // .class); // dataSource.setQueryTimeout(1800); // DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(properties.determineUrl()); // // String validationQuery = databaseDriver.getValidationQuery(); // if (validationQuery != null) { // dataSource.setTestOnBorrow(true); // dataSource.setValidationQuery(validationQuery); // } // 线上环境 JndiDataSourceLookup lookup = new JndiDataSourceLookup(); DataSource dataSource = lookup.getDataSource(jndiDataSourceName); return dataSource; } 略。。。 } # Jboss配置 # ## standalone.xml ## 在<subsystem xmlns="urn:jboss:domain:datasources:1.1">标签中增加下面的内容,增加数据源和driver节点 <datasource jndi-name="java:/jdbc/pricing" pool-name="oracleRacDS" enabled="true" use-java-context="true"> <connection-url>jdbc:oracle:thin:@ip:1521:helowin</connection-url> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <datasource-class>com.oracle</datasource-class> <driver>oracle11g</driver> <pool> <min-pool-size>10</min-pool-size> <max-pool-size>30</max-pool-size> </pool> <security> <user-name>[用户名]</user-name> <password>[密码]</password> </security> <validation> <validate-on-match>false</validate-on-match> <background-validation>false</background-validation> </validation> <timeout> <idle-timeout-minutes>60</idle-timeout-minutes> </timeout> <statement> <share-prepared-statements>false</share-prepared-statements> </statement> </datasource> <drivers> <driver name="h2" module="com.h2database.h2"> <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> </driver> <driver name="oracle11g" module="com.oracle.jdbc"> <xa-datasource-class>oracle.jdbc.xa.OracleXADataSource</xa-datasource-class> </driver> </drivers> ## modules ## modules-->system-->layers-->base-->com-->oracle-->jdbc-->main-->路径下,创建文件:module.xml,把ojdbc-6.jar放到这个目录下 <?xml version="1.0" encoding="UTF-8"?> <!-- name 为modules 目录下的目录结构 --> <module xmlns="urn:jboss:module:1.1" name="com.oracle.jdbc"> <resources> <!-- jar 路径名称,相对路径 --> <resource-root path="ojdbc-6.jar"/> </resources> <dependencies> <!-- 此模块儿依赖的相关模块儿 --> <module name="javax.api"/> <module name="javax.transaction.api"/> <module name="javax.servlet.api" optional="true"/> </dependencies> </module>
还没有评论,来说两句吧...