资源简介

SpringBoot操作多数据源(JPA+JdbcTemplate)使用HikariCP数据源进行示例。

资源截图

代码片段和文件信息

package com.pengjunlee;

import java.sql.SQLException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.pengjunlee.primary.dao.UserDao;
import com.pengjunlee.primary.entity.User;
import com.pengjunlee.primary.repository.UserRepository;
import com.pengjunlee.secondary.dao.DepartmentDao;
import com.pengjunlee.secondary.entity.Department;
import com.pengjunlee.secondary.repository.DepartmentRepository;

@SpringBootApplication
@EnableTransactionManagement // 只会回滚运行期异常
public class MyApplication {

public static void main(String[] args) throws SQLException {
ConfigurableApplicationContext context = SpringApplication.run(MyApplication.class args);

object ds1 = context.getBean(“primaryDataSource“);
System.out.println(ds1.getClass().getName());

object ds2 = context.getBean(“secondaryDataSource“);
System.out.println(ds2.getClass().getName());

UserRepository userRepository = context.getBean(UserRepository.class);
User user1 = new User();
user1.setAge(21);
user1.setName(“Tracy“);
userRepository.save(user1);

DepartmentRepository deptRepository = context.getBean(DepartmentRepository.class);
Department dept1 = new Department();
dept1.setName(“集团事业部“);
deptRepository.save(dept1);

UserDao userDao = context.getBean(UserDao.class);
userDao.addUser(30 “pengjunlee“);

DepartmentDao deptDao = context.getBean(DepartmentDao.class);
deptDao.addDept(“总裁办公室“);
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1433  2018-04-25 09:27  spring-boot-jdbc\.classpath

     文件        982  2018-04-29 11:39  spring-boot-jdbc\.project

     文件        191  2018-04-25 09:27  spring-boot-jdbc\.settings\org.eclipse.core.resources.prefs

     文件        243  2018-04-25 09:27  spring-boot-jdbc\.settings\org.eclipse.jdt.core.prefs

     文件         90  2018-04-10 08:59  spring-boot-jdbc\.settings\org.eclipse.m2e.core.prefs

     文件        145  2018-04-29 11:39  spring-boot-jdbc\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件       1211  2018-04-28 11:39  spring-boot-jdbc\pom.xml

     文件       1820  2018-04-28 11:53  spring-boot-jdbc\src\main\java\com\pengjunlee\config\DataSourceConfig.java

     文件       2432  2018-04-28 11:20  spring-boot-jdbc\src\main\java\com\pengjunlee\config\PrimaryConfig.java

     文件       2377  2018-04-28 11:21  spring-boot-jdbc\src\main\java\com\pengjunlee\config\SecondaryConfig.java

     文件       1721  2018-04-28 14:35  spring-boot-jdbc\src\main\java\com\pengjunlee\MyApplication.java

     文件        728  2018-04-28 14:33  spring-boot-jdbc\src\main\java\com\pengjunlee\primary\dao\UserDao.java

     文件        740  2018-04-28 14:28  spring-boot-jdbc\src\main\java\com\pengjunlee\primary\entity\User.java

     文件        577  2018-04-29 11:40  spring-boot-jdbc\src\main\java\com\pengjunlee\primary\impl\UserServiceImpl.java

     文件        337  2018-04-28 14:21  spring-boot-jdbc\src\main\java\com\pengjunlee\primary\repository\UserRepository.java

     文件        110  2018-04-29 11:40  spring-boot-jdbc\src\main\java\com\pengjunlee\primary\service\UserService.java

     文件        698  2018-04-28 14:34  spring-boot-jdbc\src\main\java\com\pengjunlee\secondary\dao\DepartmentDao.java

     文件        613  2018-04-28 14:24  spring-boot-jdbc\src\main\java\com\pengjunlee\secondary\entity\Department.java

     文件        358  2018-04-28 14:30  spring-boot-jdbc\src\main\java\com\pengjunlee\secondary\repository\DepartmentRepository.java

     文件       1583  2018-04-28 11:39  spring-boot-jdbc\src\main\resources\application.properties

     文件       1583  2018-04-29 11:40  spring-boot-jdbc\target\classes\application.properties

     文件       2183  2018-04-29 11:37  spring-boot-jdbc\target\classes\com\pengjunlee\config\DataSourceConfig.class

     文件       3543  2018-04-29 11:37  spring-boot-jdbc\target\classes\com\pengjunlee\config\PrimaryConfig.class

     文件       3500  2018-04-29 11:37  spring-boot-jdbc\target\classes\com\pengjunlee\config\SecondaryConfig.class

     文件       2735  2018-04-29 11:37  spring-boot-jdbc\target\classes\com\pengjunlee\MyApplication.class

     文件       1330  2018-04-29 11:37  spring-boot-jdbc\target\classes\com\pengjunlee\primary\dao\UserDao.class

     文件       1296  2018-04-29 11:37  spring-boot-jdbc\target\classes\com\pengjunlee\primary\entity\User.class

     文件        969  2018-04-29 11:40  spring-boot-jdbc\target\classes\com\pengjunlee\primary\impl\UserServiceImpl.class

     文件        434  2018-04-29 11:37  spring-boot-jdbc\target\classes\com\pengjunlee\primary\repository\UserRepository.class

     文件        181  2018-04-29 11:40  spring-boot-jdbc\target\classes\com\pengjunlee\primary\service\UserService.class

............此处省略44个文件信息

评论

共有 条评论