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
b2e3c5dd
Commit
b2e3c5dd
authored
May 14, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix order of connection pools in DataSourceBuilder
Closes gh-6013
parent
bbc37d1e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
30 deletions
+124
-30
DataSourceBuilder.java
...gframework/boot/autoconfigure/jdbc/DataSourceBuilder.java
+3
-3
DataSourceAutoConfigurationTests.java
.../autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
+0
-24
DataSourceBuilderTests.java
...ework/boot/autoconfigure/jdbc/DataSourceBuilderTests.java
+72
-0
DataSourceInitializerTests.java
...k/boot/autoconfigure/jdbc/DataSourceInitializerTests.java
+1
-3
HidePackagesClassLoader.java
...work/boot/autoconfigure/jdbc/HidePackagesClassLoader.java
+48
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBuilder.java
View file @
b2e3c5dd
...
@@ -33,8 +33,8 @@ import org.springframework.util.ClassUtils;
...
@@ -33,8 +33,8 @@ import org.springframework.util.ClassUtils;
/**
/**
* Convenience class for building a {@link DataSource} with common implementations and
* Convenience class for building a {@link DataSource} with common implementations and
* properties. If
Tomcat, HikariCP
or Commons DBCP are on the classpath one of them will
* properties. If
HikariCP, Tomcat
or Commons DBCP are on the classpath one of them will
* be selected (in that order with
Tomcat
first). In the interest of a uniform interface,
* be selected (in that order with
Hikari
first). In the interest of a uniform interface,
* and so that there can be a fallback to an embedded database if one can be detected on
* and so that there can be a fallback to an embedded database if one can be detected on
* the classpath, only a small set of common configuration properties are supported. To
* the classpath, only a small set of common configuration properties are supported. To
* inject additional properties into the result you can downcast it, or use
* inject additional properties into the result you can downcast it, or use
...
@@ -47,8 +47,8 @@ import org.springframework.util.ClassUtils;
...
@@ -47,8 +47,8 @@ import org.springframework.util.ClassUtils;
public
class
DataSourceBuilder
{
public
class
DataSourceBuilder
{
private
static
final
String
[]
DATA_SOURCE_TYPE_NAMES
=
new
String
[]
{
private
static
final
String
[]
DATA_SOURCE_TYPE_NAMES
=
new
String
[]
{
"org.apache.tomcat.jdbc.pool.DataSource"
,
"com.zaxxer.hikari.HikariDataSource"
,
"com.zaxxer.hikari.HikariDataSource"
,
"org.apache.tomcat.jdbc.pool.DataSource"
,
"org.apache.commons.dbcp2.BasicDataSource"
};
"org.apache.commons.dbcp2.BasicDataSource"
};
private
Class
<?
extends
DataSource
>
type
;
private
Class
<?
extends
DataSource
>
type
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
View file @
b2e3c5dd
...
@@ -16,8 +16,6 @@
...
@@ -16,8 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.Driver
;
import
java.sql.Driver
;
import
java.sql.DriverPropertyInfo
;
import
java.sql.DriverPropertyInfo
;
...
@@ -303,26 +301,4 @@ public class DataSourceAutoConfigurationTests {
...
@@ -303,26 +301,4 @@ public class DataSourceAutoConfigurationTests {
}
}
private
static
final
class
HidePackagesClassLoader
extends
URLClassLoader
{
private
final
String
[]
hiddenPackages
;
private
HidePackagesClassLoader
(
String
...
hiddenPackages
)
{
super
(
new
URL
[
0
],
DataSourceAutoConfigurationTests
.
class
.
getClassLoader
());
this
.
hiddenPackages
=
hiddenPackages
;
}
@Override
protected
Class
<?>
loadClass
(
String
name
,
boolean
resolve
)
throws
ClassNotFoundException
{
for
(
String
hiddenPackage
:
this
.
hiddenPackages
)
{
if
(
name
.
startsWith
(
hiddenPackage
))
{
throw
new
ClassNotFoundException
();
}
}
return
super
.
loadClass
(
name
,
resolve
);
}
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBuilderTests.java
0 → 100644
View file @
b2e3c5dd
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
java.io.Closeable
;
import
java.io.IOException
;
import
javax.sql.DataSource
;
import
com.zaxxer.hikari.HikariDataSource
;
import
org.apache.commons.dbcp2.BasicDataSource
;
import
org.junit.After
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DataSourceBuilder}.
*
* @author Stephane Nicoll
*/
public
class
DataSourceBuilderTests
{
private
DataSource
dataSource
;
@After
public
void
shutdownDataSource
()
throws
IOException
{
if
(
this
.
dataSource
instanceof
Closeable
)
{
((
Closeable
)
this
.
dataSource
).
close
();
}
}
@Test
public
void
defaultToHikari
()
{
this
.
dataSource
=
DataSourceBuilder
.
create
()
.
url
(
"jdbc:h2:test"
).
build
();
assertThat
(
this
.
dataSource
).
isInstanceOf
(
HikariDataSource
.
class
);
}
@Test
public
void
defaultToTomcatIfHikariIsNotAvailable
()
{
this
.
dataSource
=
DataSourceBuilder
.
create
(
new
HidePackagesClassLoader
(
"com.zaxxer.hikari"
))
.
url
(
"jdbc:h2:test"
).
build
();
assertThat
(
this
.
dataSource
).
isInstanceOf
(
org
.
apache
.
tomcat
.
jdbc
.
pool
.
DataSource
.
class
);
}
@Test
public
void
defaultToCommonsDbcp2AsLastResort
()
{
this
.
dataSource
=
DataSourceBuilder
.
create
(
new
HidePackagesClassLoader
(
"com.zaxxer.hikari"
,
"org.apache.tomcat.jdbc.pool"
))
.
url
(
"jdbc:h2:test"
).
build
();
assertThat
(
this
.
dataSource
).
isInstanceOf
(
BasicDataSource
.
class
);
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java
View file @
b2e3c5dd
...
@@ -95,9 +95,7 @@ public class DataSourceInitializerTests {
...
@@ -95,9 +95,7 @@ public class DataSourceInitializerTests {
public
void
testTwoDataSources
()
throws
Exception
{
public
void
testTwoDataSources
()
throws
Exception
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"datasource.one.url=jdbc:hsqldb:mem:/one"
,
"datasource.one.url=jdbc:hsqldb:mem:/one"
,
"datasource.one.driverClassName=org.hsqldb.Driver"
,
"datasource.two.url=jdbc:hsqldb:mem:/two"
);
"datasource.two.url=jdbc:hsqldb:mem:/two"
,
"datasource.two.driverClassName=org.hsqldb.Driver"
);
this
.
context
.
register
(
TwoDataSources
.
class
,
DataSourceInitializer
.
class
,
this
.
context
.
register
(
TwoDataSources
.
class
,
DataSourceInitializer
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
DataSourceProperties
.
class
);
PropertyPlaceholderAutoConfiguration
.
class
,
DataSourceProperties
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HidePackagesClassLoader.java
0 → 100644
View file @
b2e3c5dd
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
/**
* Test {@link URLClassLoader} that hides configurable packages.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
final
class
HidePackagesClassLoader
extends
URLClassLoader
{
private
final
String
[]
hiddenPackages
;
HidePackagesClassLoader
(
String
...
hiddenPackages
)
{
super
(
new
URL
[
0
],
HidePackagesClassLoader
.
class
.
getClassLoader
());
this
.
hiddenPackages
=
hiddenPackages
;
}
@Override
protected
Class
<?>
loadClass
(
String
name
,
boolean
resolve
)
throws
ClassNotFoundException
{
for
(
String
hiddenPackage
:
this
.
hiddenPackages
)
{
if
(
name
.
startsWith
(
hiddenPackage
))
{
throw
new
ClassNotFoundException
();
}
}
return
super
.
loadClass
(
name
,
resolve
);
}
}
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