Yml:[Java] 纯文本查看 复制代码 spring:
datasource:
jndi-name: jdbc/****
Tmocat:
[Java] 纯文本查看 复制代码 <Resource
name="jdbc/grid-market"
url="jdbc:mysql://localhost:3306/***?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8"
username="root"
password="*****"
type="com.alibaba.druid.pool.DruidDataSource"
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="30"
maxWait="10000"
maxActive="100"
/>
DataSourceOneConfig:
[Java] 纯文本查看 复制代码 @Configuration //注册到springboot 容器中
@MapperScan(basePackages = {""}, sqlSessionTemplateRef = "test1SqlSessionTemplate")
public class DataSourceOneConfig {
//application.properties中的jndi名称
@Value("${spring.datasource.jndi-name}")
private String jndiName;
@Bean(name = "test1DataSource", destroyMethod = "") // destroy method is disabled for Weblogic update app ability
@ConfigurationProperties(prefix = "spring.datasource.bigdata")
public DataSource bigdataDs() throws NamingException {
JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
bean.setJndiName(jndiName);
bean.setProxyInterface(DataSource.class);
bean.setLookupOnStartup(false);
bean.afterPropertiesSet();
return (DataSource) bean.getObject();
}
@Bean(name = "test1SqlSessionFactory")
public SqlSessionFactory testSqlSessionFactory(@Qualifier("test1DataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource((javax.sql.DataSource) dataSource);
//加载其他文件,如mapper.xml
// bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test1/*.xml"));
return bean.getObject();
}
//事务管理
@Bean(name = "test1TransactionManager")
public DataSourceTransactionManager testTransactionManager(@Qualifier("test1DataSource") DataSource dataSource) {
return new DataSourceTransactionManager((javax.sql.DataSource) dataSource);
}
@Bean(name = "test1SqlSessionTemplate")
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("test1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
这是百度到的,,但是不能用
|