67,511
社区成员
发帖
与我相关
我的任务
分享
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.3.4</version>
</dependency>
<!-- ===========================================source edu db start============================================= -->
<!-- 配置数据源使用的是Druid数据源 -->
<bean name="dataSource_edu" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
destroy-method="close">
<property name="url" value="${edu.jdbc.url}" />
<property name="username" value="${edu.jdbc.username}" />
<property name="password" value="${edu.jdbc.password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="0" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="20" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="0" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="60000" />
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="33" />
<!-- 用来检测有效SQL -->
<property name="validationQuery" value="SELECT 1 FROM DUAL" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="25200000" />
<!-- 打开removeAbandoned功能 -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
<!-- 监控数据库 -->
<property name="filters" value="stat,wall" />
</bean>
<!-- Mybatis Mapper文件 -->
<bean id="sqlSessionFactory_edu" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource_edu" />
<property name="mapperLocations">
<array>
<value>classpath*:com/ssic/cloud/***/source/dao/edu/mapper/*Mapper.xml</value>
</array>
</property>
<property name="typeAliasesPackage" value="com.sm.**.model;com.ssic.**.mapper;com.ssic.**.entities;" />
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=${jdbc.dialect}
reasonable=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager_edu" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource_edu" />
</bean>
<!-- 注解方式配置事物 -->
<tx:annotation-driven transaction-manager="transactionManager_edu" />
<!-- 管理指定的mapper文件 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ssic.cloud.dbtools.data.source.dao.edu.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_edu"/>
</bean>
<!-- ===========================================source edu db end============================================== -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
#etl b2b order db
etl.b2b.order.jdbc.driver-class-name=com.mysql.jdbc.Driver
etl.b2b.order.jdbc.dialect=mysql
etl.b2b.order.jdbc.jdbc-url=jdbc:mysql://x.x.x.x:3306/ssic_order?useUnicode=true&characterEncoding=utf-8
etl.b2b.order.jdbc.username=dba
etl.b2b.order.jdbc.password=ccc
#etl b2b goods db
etl.b2b.goods.jdbc.driver-class-name=com.mysql.jdbc.Driver
etl.b2b.goods.jdbc.dialect=mysql
etl.b2b.goods.jdbc.url=jdbc:mysql://x.x.x.x:3306/ssic_goods?useUnicode=true&characterEncoding=utf-8
etl.b2b.goods.jdbc.username=dba
etl.b2b.goods.jdbc.password=ccc
@EnableAutoConfiguration
@SpringBootApplication
@PropertySource("classpath:config/application.properties")
//@ComponentScan("com.ssic.cloud.etl")
public class Program {
public static void main(String[] args) {
SpringApplication.run(Program.class, args);
}
}
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import tk.mybatis.spring.annotation.MapperScan;
/*goods数据库*/
@Configuration
@MapperScan(basePackages = "com.ssic.cloud.etl.business.B2BB1.dao.goods.mapper", sqlSessionTemplateRef = "goodsSqlSessionTemplate")
public class DataSourceGoodsConfig {
@Bean(name = "goodsDataSource")
@ConfigurationProperties(prefix = "etl.b2b.goods.jdbc")
//@Primary
public DataSource testDataSource() throws Exception {
return DataSourceBuilder.create().type(com.alibaba.druid.pool.DruidDataSource.class).build();
}
@Bean(name = "goodsSqlSessionFactory")
//@Primary /*此处必须在主数据库的数据源配置上加上@Primary*/
public SqlSessionFactory testSqlSessionFactory(@Qualifier("goodsDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
/*加载mybatis全局配置文件*/
//bean.setConfigLocation(new PathMatchingResourcePatternResolver().getResource("classpath:mybatis/mybatis-config.xml"));
/*加载所有的mapper.xml映射文件*/
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:**/dao/goods/mapper/*.xml"));
return bean.getObject();
}
@Bean(name = "goodsTransactionManager")
//@Primary
public DataSourceTransactionManager testTransactionManager(@Qualifier("goodsDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "goodsSqlSessionTemplate")
//@Primary
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("goodsSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
Thu Nov 22 13:35:04 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
13:35:05.150 [http-nio-8080-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseSelectProvider.dynamicSQL). Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseSelectProvider] with root cause
java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.base.BaseSelectProvider.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
13:38:07.744 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at tk.mybatis.spring.mapper.SpringBootBindUtil$SpringBoot2Bind.bind(SpringBootBindUtil.java:129) ~[mapper-spring-boot-autoconfigure-1.2.3.jar:?]
at tk.mybatis.spring.mapper.SpringBootBindUtil.bind(SpringBootBindUtil.java:58) ~[mapper-spring-boot-autoconfigure-1.2.3.jar:?]
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
Caused by: java.util.NoSuchElementException: No value bound
at org.springframework.boot.context.properties.bind.BindResult.get(BindResult.java:56) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]