Springboot integration of multiple data sources: one mysql and one Oracle (1) pre-preparation

Hello, everyone, hello, I am Yang Yang, yes is the most handsome cub, these two days, just in the integration of multi-data source function, today, I will tell you about a sub-multi-data source

Multiple data sources, one mysql and one Oracle

First of all, let’s make preparations:

Install oracle

Oracle 11g oracle 11g Oracle 11g Oracle 11g Oracle 11G

Connect the oracle

Method (1) IDEA Connects to Oracle

After oracle is installed, we definitely need to test to see if there is any problem. The database with IDEA is connected as follows

Mode (2) Navicat links to Oracle

As shown in the figure below

Create the table that you will test later

Create an Oracle table based on the database you just completed: if you use Navicat remember to create it under the schema SYSMAN

create table USERTEST
(
  ID   NUMBER default 1 not null,
  NAME VARCHAR2(20) default null
)
Copy the code

Insert whatever data you want into it

Create corresponding levels

xml

<mapper namespace="com.ermei.admui.sys.mapper.TestOracleMapper">

  <select id="queryInfo" resultType="string">
      select NAME from USERTEST
  </select>
</mapper>
Copy the code

Mapper

/** * query oracleMapper **@author yanglei
 */
public interface TestOracleMapper {
    /** * query */
    List<String> queryInfo(a);
     
}
Copy the code

The service and implementation

/ * * *@author yanglei
 * @desc
 * @date2020/9/4 * /
public interface TestOracleService {

    List<String> queryInfo(a);

}


/ * * *@author yanglei
 * @desc
 * @date2020/9/4 * /

@Service
@DataSource(value = DataSourceType.SLAVE)
public class TestOracleServiceImpl implements TestOracleService {

    @Resource
    private TestOracleMapper testOracleMapper;



    @Override
    public List<String> queryInfo(a) {
        returntestOracleMapper.queryInfo(); }}Copy the code

Create a controller

/ * * *@author yanglei
 * @desc
 * @date2020/9/4 * /
@Api("ORACLE Controller")
@RestController
public class TestOracleController {

    @Resource
    private TestOracleService testOracleService;


    @apiOperation (value = "test ")
    @GetMapping("oracle/queryInfo")
    public List<String> queryInfo(a){
        returntestOracleService.queryInfo(); }}Copy the code

Prepare the oracle8 jar package

The reason is that Oracle is charged and cannot be imported remotely. It can only be loaded into the project by configuring local libraries

Download from oracle’s official website

Click download, will jump to login, login after you can download or online resources, in fact, 6 or more versions should be ok

After downloading, go to the location of your oracle.jar file, open CMD, and type the following command

MVN install: install-file-dgroupid =com.oracle -dartifactid =ojdbc8 -dversion =8.0.0.1 -dpackaging =jar – Dfile = ‪ D: \ commonUseDevelop \ ojdbc8 jar

If Maven returns an error while running, modify the command to replace the characters you have problems with

Bring in the Maven coordinates you just saw

<! -- oracle --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc8</artifactId> <version>8.0. 01.</version>
        </dependency>
Copy the code

Here we are, ready for the core of the next canto