Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
2cf93f89
Commit
2cf93f89
authored
Jan 26, 2017
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
daf6be46
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
28 additions
and
40 deletions
+28
-40
pom.xml
spring-boot-dependencies/pom.xml
+7
-5
howto.adoc
spring-boot-docs/src/main/asciidoc/howto.adoc
+6
-6
BasicDataSourceExample.java
...org/springframework/boot/jdbc/BasicDataSourceExample.java
+1
-0
CompleteTwoDataSourcesExample.java
...ingframework/boot/jdbc/CompleteTwoDataSourcesExample.java
+4
-9
ConfigurableDataSourceExample.java
...ingframework/boot/jdbc/ConfigurableDataSourceExample.java
+2
-2
SimpleDataSourceExample.java
...rg/springframework/boot/jdbc/SimpleDataSourceExample.java
+1
-2
SimpleTwoDataSourcesExample.java
...pringframework/boot/jdbc/SimpleTwoDataSourcesExample.java
+2
-6
BasicDataSourceExampleTests.java
...pringframework/boot/jdbc/BasicDataSourceExampleTests.java
+1
-0
CompleteTwoDataSourcesExampleTests.java
...amework/boot/jdbc/CompleteTwoDataSourcesExampleTests.java
+0
-2
SampleApp.java
...rc/test/java/org/springframework/boot/jdbc/SampleApp.java
+2
-2
SimpleTwoDataSourcesExampleTests.java
...framework/boot/jdbc/SimpleTwoDataSourcesExampleTests.java
+2
-6
No files found.
spring-boot-dependencies/pom.xml
View file @
2cf93f89
<?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"
>
<?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>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<artifactId>
spring-boot-dependencies
</artifactId>
...
@@ -1961,9 +1963,9 @@
...
@@ -1961,9 +1963,9 @@
<version>
${mongodb.version}
</version>
<version>
${mongodb.version}
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.mortbay.jasper
</groupId>
<groupId>
org.mortbay.jasper
</groupId>
<artifactId>
apache-el
</artifactId>
<artifactId>
apache-el
</artifactId>
<version>
${jetty-el.version}
</version>
<version>
${jetty-el.version}
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.neo4j
</groupId>
<groupId>
org.neo4j
</groupId>
...
@@ -2669,4 +2671,4 @@
...
@@ -2669,4 +2671,4 @@
<id>
integration-test
</id>
<id>
integration-test
</id>
</profile>
</profile>
</profiles>
</profiles>
</project>
</project>
\ No newline at end of file
spring-boot-docs/src/main/asciidoc/howto.adoc
View file @
2cf93f89
...
@@ -1732,11 +1732,10 @@ You can apply the same principle if you are configuring a custom JNDI `DataSourc
...
@@ -1732,11 +1732,10 @@ You can apply the same principle if you are configuring a custom JNDI `DataSourc
}
}
----
----
Spring Boot also provides a utility builder class `DataSourceBuilder` that can be used to
Spring Boot also provides a utility builder class `DataSourceBuilder` that can be used
create one of the standard data sources (if it is on the classpath). The builder can
to create one of the standard data sources (if it is on the classpath). The builder can
detect the one to use based on what's available on the classpath. It also auto detects the
detect the one to use based on the ones available on the classpath and it also auto
driver based on the JDBC url.
detects the driver based on the JDBC url.
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
----
...
@@ -1759,7 +1758,7 @@ There is a catch however. Because the actual type of the connection pool is not
...
@@ -1759,7 +1758,7 @@ There is a catch however. Because the actual type of the connection pool is not
no keys are generated in the metadata for your custom `DataSource` and no completion is
no keys are generated in the metadata for your custom `DataSource` and no completion is
available in your IDE (The `DataSource` interface doesn't expose any property). Also, if
available in your IDE (The `DataSource` interface doesn't expose any property). Also, if
you happen to _only_ have Hikari on the classpath, this basic setup will not work because
you happen to _only_ have Hikari on the classpath, this basic setup will not work because
Hikari has no `url` parameter (but a `jdbcUrl` parameter). You
should
have to rewrite
Hikari has no `url` parameter (but a `jdbcUrl` parameter). You
will
have to rewrite
your configuration as follows:
your configuration as follows:
[source,properties,indent=0]
[source,properties,indent=0]
...
@@ -1861,6 +1860,7 @@ This final example configures two data sources on custom namespaces with the sam
...
@@ -1861,6 +1860,7 @@ This final example configures two data sources on custom namespaces with the sam
than what Spring Boot would do in auto-configuration.
than what Spring Boot would do in auto-configuration.
[[howto-use-spring-data-repositories]]
[[howto-use-spring-data-repositories]]
=== Use Spring Data repositories
=== Use Spring Data repositories
Spring Data can create implementations for you of `@Repository` interfaces of various
Spring Data can create implementations for you of `@Repository` interfaces of various
...
...
spring-boot-docs/src/main/java/org/springframework/boot/jdbc/BasicDataSourceExample.java
View file @
2cf93f89
...
@@ -45,4 +45,5 @@ public class BasicDataSourceExample {
...
@@ -45,4 +45,5 @@ public class BasicDataSourceExample {
// end::configuration[]
// end::configuration[]
}
}
}
}
spring-boot-docs/src/main/java/org/springframework/boot/jdbc/CompleteTwoDataSourcesExample.java
View file @
2cf93f89
...
@@ -25,8 +25,8 @@ import org.springframework.context.annotation.Configuration;
...
@@ -25,8 +25,8 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.context.annotation.Primary
;
/**
/**
* Example configuration for configuring two data sources with what Spring Boot does
* Example configuration for configuring two data sources with what Spring Boot does
in
*
in
auto-configuration.
* auto-configuration.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
...
@@ -50,9 +50,7 @@ public class CompleteTwoDataSourcesExample {
...
@@ -50,9 +50,7 @@ public class CompleteTwoDataSourcesExample {
@Primary
@Primary
@ConfigurationProperties
(
"app.datasource.foo"
)
@ConfigurationProperties
(
"app.datasource.foo"
)
public
DataSource
fooDataSource
()
{
public
DataSource
fooDataSource
()
{
return
fooDataSourceProperties
()
return
fooDataSourceProperties
().
initializeDataSourceBuilder
().
build
();
.
initializeDataSourceBuilder
()
.
build
();
}
}
@Bean
@Bean
...
@@ -61,13 +59,10 @@ public class CompleteTwoDataSourcesExample {
...
@@ -61,13 +59,10 @@ public class CompleteTwoDataSourcesExample {
return
new
DataSourceProperties
();
return
new
DataSourceProperties
();
}
}
@Bean
@Bean
@ConfigurationProperties
(
"app.datasource.bar"
)
@ConfigurationProperties
(
"app.datasource.bar"
)
public
DataSource
barDataSource
()
{
public
DataSource
barDataSource
()
{
return
barDataSourceProperties
()
return
barDataSourceProperties
().
initializeDataSourceBuilder
().
build
();
.
initializeDataSourceBuilder
()
.
build
();
}
}
// end::configuration[]
// end::configuration[]
...
...
spring-boot-docs/src/main/java/org/springframework/boot/jdbc/ConfigurableDataSourceExample.java
View file @
2cf93f89
...
@@ -52,10 +52,10 @@ public class ConfigurableDataSourceExample {
...
@@ -52,10 +52,10 @@ public class ConfigurableDataSourceExample {
@ConfigurationProperties
(
"app.datasource"
)
@ConfigurationProperties
(
"app.datasource"
)
public
HikariDataSource
dataSource
(
DataSourceProperties
properties
)
{
public
HikariDataSource
dataSource
(
DataSourceProperties
properties
)
{
return
(
HikariDataSource
)
properties
.
initializeDataSourceBuilder
()
return
(
HikariDataSource
)
properties
.
initializeDataSourceBuilder
()
.
type
(
HikariDataSource
.
class
)
.
type
(
HikariDataSource
.
class
).
build
();
.
build
();
}
}
// end::configuration[]
// end::configuration[]
}
}
}
}
spring-boot-docs/src/main/java/org/springframework/boot/jdbc/SimpleDataSourceExample.java
View file @
2cf93f89
...
@@ -43,8 +43,7 @@ public class SimpleDataSourceExample {
...
@@ -43,8 +43,7 @@ public class SimpleDataSourceExample {
@ConfigurationProperties
(
"app.datasource"
)
@ConfigurationProperties
(
"app.datasource"
)
public
HikariDataSource
dataSource
()
{
public
HikariDataSource
dataSource
()
{
return
(
HikariDataSource
)
DataSourceBuilder
.
create
()
return
(
HikariDataSource
)
DataSourceBuilder
.
create
()
.
type
(
HikariDataSource
.
class
)
.
type
(
HikariDataSource
.
class
).
build
();
.
build
();
}
}
// end::configuration[]
// end::configuration[]
...
...
spring-boot-docs/src/main/java/org/springframework/boot/jdbc/SimpleTwoDataSourcesExample.java
View file @
2cf93f89
...
@@ -53,18 +53,14 @@ public class SimpleTwoDataSourcesExample {
...
@@ -53,18 +53,14 @@ public class SimpleTwoDataSourcesExample {
@Primary
@Primary
@ConfigurationProperties
(
"app.datasource.foo"
)
@ConfigurationProperties
(
"app.datasource.foo"
)
public
DataSource
fooDataSource
()
{
public
DataSource
fooDataSource
()
{
return
fooDataSourceProperties
()
return
fooDataSourceProperties
().
initializeDataSourceBuilder
().
build
();
.
initializeDataSourceBuilder
()
.
build
();
}
}
@Bean
@Bean
@ConfigurationProperties
(
"app.datasource.bar"
)
@ConfigurationProperties
(
"app.datasource.bar"
)
public
BasicDataSource
barDataSource
()
{
public
BasicDataSource
barDataSource
()
{
return
(
BasicDataSource
)
DataSourceBuilder
.
create
()
return
(
BasicDataSource
)
DataSourceBuilder
.
create
()
.
type
(
BasicDataSource
.
class
)
.
type
(
BasicDataSource
.
class
).
build
();
.
build
();
}
}
// end::configuration[]
// end::configuration[]
...
...
spring-boot-docs/src/test/java/org/springframework/boot/jdbc/BasicDataSourceExampleTests.java
View file @
2cf93f89
...
@@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
/**
* Test for {@link BasicDataSourceExample}.
* Test for {@link BasicDataSourceExample}.
*
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
...
...
spring-boot-docs/src/test/java/org/springframework/boot/jdbc/CompleteTwoDataSourcesExampleTests.java
View file @
2cf93f89
...
@@ -47,12 +47,10 @@ public class CompleteTwoDataSourcesExampleTests {
...
@@ -47,12 +47,10 @@ public class CompleteTwoDataSourcesExampleTests {
@Test
@Test
public
void
validateConfiguration
()
throws
SQLException
{
public
void
validateConfiguration
()
throws
SQLException
{
assertThat
(
this
.
context
.
getBeansOfType
(
DataSource
.
class
)).
hasSize
(
2
);
assertThat
(
this
.
context
.
getBeansOfType
(
DataSource
.
class
)).
hasSize
(
2
);
DataSource
dataSource
=
this
.
context
.
getBean
(
DataSource
.
class
);
DataSource
dataSource
=
this
.
context
.
getBean
(
DataSource
.
class
);
assertThat
(
this
.
context
.
getBean
(
"fooDataSource"
)).
isSameAs
(
dataSource
);
assertThat
(
this
.
context
.
getBean
(
"fooDataSource"
)).
isSameAs
(
dataSource
);
assertThat
(
dataSource
.
getConnection
().
getMetaData
().
getURL
())
assertThat
(
dataSource
.
getConnection
().
getMetaData
().
getURL
())
.
startsWith
(
"jdbc:h2:mem:"
);
.
startsWith
(
"jdbc:h2:mem:"
);
DataSource
barDataSource
=
this
.
context
.
getBean
(
"barDataSource"
,
DataSource
barDataSource
=
this
.
context
.
getBean
(
"barDataSource"
,
DataSource
.
class
);
DataSource
.
class
);
assertThat
(
barDataSource
.
getConnection
().
getMetaData
().
getURL
())
assertThat
(
barDataSource
.
getConnection
().
getMetaData
().
getURL
())
...
...
spring-boot-docs/src/test/java/org/springframework/boot/jdbc/SampleApp.java
View file @
2cf93f89
...
@@ -23,8 +23,8 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
...
@@ -23,8 +23,8 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
/**
/**
* A sample {@link SpringBootConfiguration} that only enables the auto-configuration
* A sample {@link SpringBootConfiguration} that only enables the auto-configuration
for
*
for
the {@link DataSource}.
* the {@link DataSource}.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
...
...
spring-boot-docs/src/test/java/org/springframework/boot/jdbc/SimpleTwoDataSourcesExampleTests.java
View file @
2cf93f89
...
@@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
properties
=
{
@SpringBootTest
(
properties
=
{
"app.datasource.bar.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1"
,
"app.datasource.bar.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1"
,
"app.datasource.bar.max-total=42"
})
"app.datasource.bar.max-total=42"
})
@Import
(
SimpleTwoDataSourcesExample
.
SimpleDataSourcesConfiguration
.
class
)
@Import
(
SimpleTwoDataSourcesExample
.
SimpleDataSourcesConfiguration
.
class
)
public
class
SimpleTwoDataSourcesExampleTests
{
public
class
SimpleTwoDataSourcesExampleTests
{
...
@@ -50,16 +49,13 @@ public class SimpleTwoDataSourcesExampleTests {
...
@@ -50,16 +49,13 @@ public class SimpleTwoDataSourcesExampleTests {
@Test
@Test
public
void
validateConfiguration
()
throws
SQLException
{
public
void
validateConfiguration
()
throws
SQLException
{
assertThat
(
this
.
context
.
getBeansOfType
(
DataSource
.
class
)).
hasSize
(
2
);
assertThat
(
this
.
context
.
getBeansOfType
(
DataSource
.
class
)).
hasSize
(
2
);
DataSource
dataSource
=
this
.
context
.
getBean
(
DataSource
.
class
);
DataSource
dataSource
=
this
.
context
.
getBean
(
DataSource
.
class
);
assertThat
(
this
.
context
.
getBean
(
"fooDataSource"
)).
isSameAs
(
dataSource
);
assertThat
(
this
.
context
.
getBean
(
"fooDataSource"
)).
isSameAs
(
dataSource
);
assertThat
(
dataSource
.
getConnection
().
getMetaData
().
getURL
())
assertThat
(
dataSource
.
getConnection
().
getMetaData
().
getURL
())
.
startsWith
(
"jdbc:h2:mem:"
);
.
startsWith
(
"jdbc:h2:mem:"
);
BasicDataSource
barDataSource
=
this
.
context
.
getBean
(
"barDataSource"
,
BasicDataSource
barDataSource
=
this
.
context
.
getBean
(
"barDataSource"
,
BasicDataSource
.
class
);
BasicDataSource
.
class
);
assertThat
(
barDataSource
.
getUrl
())
assertThat
(
barDataSource
.
getUrl
()).
isEqualTo
(
"jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1"
);
.
isEqualTo
(
"jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1"
);
assertThat
(
barDataSource
.
getMaxTotal
()).
isEqualTo
(
42
);
assertThat
(
barDataSource
.
getMaxTotal
()).
isEqualTo
(
42
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment