forked from javastacks/spring-boot-best-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a09e8ae
commit 2e9426b
Showing
7 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>spring-boot-best-practice</artifactId> | ||
<groupId>cn.javastack</groupId> | ||
<version>1.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-boot-druid</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid-spring-boot-starter</artifactId> | ||
<version>1.1.14</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jdbc</artifactId> | ||
<version>2.1.3.RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.oracle</groupId> | ||
<artifactId>ojdbc6</artifactId> | ||
<version>11.2.0.1.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
38 changes: 38 additions & 0 deletions
38
spring-boot-druid/src/main/java/cn/javastack/springboot/banner/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cn.javastack.springboot.banner; | ||
|
||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; | ||
import org.springframework.boot.Banner; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Primary; | ||
|
||
import javax.sql.DataSource; | ||
|
||
/** | ||
* 微信公众号:Java技术栈 | ||
*/ | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
new SpringApplicationBuilder(Application.class).bannerMode(Banner.Mode.CONSOLE) | ||
.run(args); | ||
} | ||
|
||
@Primary | ||
@Bean | ||
@ConfigurationProperties("spring.datasource.druid.one") | ||
public DataSource dataSourceOne() { | ||
return DruidDataSourceBuilder.create().build(); | ||
} | ||
|
||
@Bean | ||
@ConfigurationProperties("spring.datasource.druid.two") | ||
public DataSource dataSourceTwo() { | ||
return DruidDataSourceBuilder.create().build(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>spring-boot-best-practice</artifactId> | ||
<groupId>cn.javastack</groupId> | ||
<version>1.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-boot-properties</artifactId> | ||
|
||
|
||
</project> |
33 changes: 33 additions & 0 deletions
33
spring-boot-properties/src/main/java/cn/javastack/springboot/properties/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cn.javastack.springboot.properties; | ||
|
||
import cn.javastack.springboot.properties.props.TomProperties; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* 微信公众号:Java技术栈 | ||
*/ | ||
@SpringBootApplication | ||
@EnableConfigurationProperties | ||
public class Application { | ||
|
||
@Autowired | ||
private TomProperties tomProperties; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class); | ||
} | ||
|
||
@Bean | ||
public CommandLineRunner commandLineRunner() { | ||
return (args) -> { | ||
System.out.println(tomProperties); | ||
}; | ||
} | ||
|
||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...boot-properties/src/main/java/cn/javastack/springboot/properties/props/TomProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cn.javastack.springboot.properties.props; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.ConstructorBinding; | ||
import org.springframework.boot.context.properties.bind.DefaultValue; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 微信公众号:Java技术栈 | ||
*/ | ||
@ConstructorBinding | ||
@ConfigurationProperties(prefix = "tom") | ||
public class TomProperties { | ||
|
||
private String name; | ||
private String sex; | ||
private int age; | ||
private String country; | ||
private Date entryTime; | ||
|
||
public TomProperties(String name, | ||
String sex, | ||
int age, | ||
@DefaultValue("China") String country, | ||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date entryTime) { | ||
this.name = name; | ||
this.sex = sex; | ||
this.age = age; | ||
this.country = country; | ||
this.entryTime = entryTime; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getSex() { | ||
return sex; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
public Date getEntryTime() { | ||
return entryTime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TomProperties{" + | ||
"name='" + name + '\'' + | ||
", sex='" + sex + '\'' + | ||
", age=" + age + | ||
", country='" + country + '\'' + | ||
", entryTime=" + entryTime + | ||
'}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tom: | ||
name: Tom | ||
sex: man | ||
age: 18 | ||
entry-time: 2012-12-12 12:00:00 |