官方文档指南启动成功
This commit is contained in:
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
58
pom.xml
Normal file
58
pom.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>top.fjy8018</groupId>
|
||||
<artifactId>jpadatasource</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>jpadatasource</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
13
sql.sql
Normal file
13
sql.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
DROP DATABASE IF EXISTS jpa_test;
|
||||
CREATE DATABASE jpa_test
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
COLLATE utf8mb4_general_ci;
|
||||
GRANT ALL ON jpa_test.* TO financial_adminer@'%'
|
||||
IDENTIFIED BY 'financial_adminer_pass';
|
||||
|
||||
DROP DATABASE IF EXISTS jpa_test_bak;
|
||||
CREATE DATABASE jpa_test_bak
|
||||
DEFAULT CHARACTER SET utf8mb4
|
||||
COLLATE utf8mb4_general_ci;
|
||||
GRANT ALL ON jpa_test_bak.* TO financial_adminer@'%'
|
||||
IDENTIFIED BY 'financial_adminer_pass';
|
||||
@@ -0,0 +1,13 @@
|
||||
package top.fjy8018.jpadatasource;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class JpadatasourceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(JpadatasourceApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package top.fjy8018.jpadatasource.config;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* @author F嘉阳
|
||||
* @date 2019-03-30 9:24
|
||||
*/
|
||||
@Configuration
|
||||
public class DataAccessConfig {
|
||||
@Bean
|
||||
@Primary
|
||||
@ConfigurationProperties("spring.datasource.first")
|
||||
public DataSourceProperties firstDataSourceProperties() {
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@ConfigurationProperties("spring.datasource.first.configuration")
|
||||
public HikariDataSource firstDataSource() {
|
||||
return firstDataSourceProperties().initializeDataSourceBuilder()
|
||||
.type(HikariDataSource.class).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("spring.datasource.second")
|
||||
public DataSourceProperties secondDataSourceProperties() {
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties("spring.datasource.second.configuration")
|
||||
public HikariDataSource secondDataSource() {
|
||||
return secondDataSourceProperties().initializeDataSourceBuilder()
|
||||
.type(HikariDataSource.class).build();
|
||||
}
|
||||
}
|
||||
|
||||
22
src/main/java/top/fjy8018/jpadatasource/entity/Product.java
Normal file
22
src/main/java/top/fjy8018/jpadatasource/entity/Product.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package top.fjy8018.jpadatasource.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author F嘉阳
|
||||
* @date 2019-03-30 9:11
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
public class Product {
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer price;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package top.fjy8018.jpadatasource.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import top.fjy8018.jpadatasource.entity.Product;
|
||||
|
||||
/**
|
||||
* @author F嘉阳
|
||||
* @date 2019-03-30 9:12
|
||||
*/
|
||||
public interface ProductRepository extends JpaRepository<Product, String> {
|
||||
}
|
||||
26
src/main/resources/application.yml
Normal file
26
src/main/resources/application.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
spring:
|
||||
datasource:
|
||||
first:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: financial_adminer
|
||||
password: financial_adminer_pass
|
||||
url: jdbc:mysql://120.79.226.26/jpa_test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
|
||||
configuration:
|
||||
maximum-pool-size: 30
|
||||
second:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: financial_adminer
|
||||
password: financial_adminer_pass
|
||||
url: jdbc:mysql://120.79.226.26/jpa_test_bak?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
|
||||
configuration:
|
||||
maximum-pool-size: 20
|
||||
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
show-sql: true
|
||||
database-platform: org.hibernate.dialect.MySQL55Dialect
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
use_sql_comments: true
|
||||
@@ -0,0 +1,16 @@
|
||||
package top.fjy8018.jpadatasource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class JpadatasourceApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user