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
f3aa236e
Commit
f3aa236e
authored
Feb 11, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
187d26ae
a8f4708f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
214 additions
and
0 deletions
+214
-0
pom.xml
spring-boot-devtools/pom.xml
+14
-0
DevToolsDataSourceAutoConfiguration.java
...ls/autoconfigure/DevToolsDataSourceAutoConfiguration.java
+88
-0
spring.factories
...oot-devtools/src/main/resources/META-INF/spring.factories
+1
-0
DevToolsDataSourceAutoConfigurationTests.java
...toconfigure/DevToolsDataSourceAutoConfigurationTests.java
+111
-0
No files found.
spring-boot-devtools/pom.xml
View file @
f3aa236e
...
...
@@ -39,6 +39,11 @@
<artifactId>
log4j-core
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-jdbc
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
...
...
@@ -71,6 +76,11 @@
<optional>
true
</optional>
</dependency>
<!-- Test -->
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
...
...
@@ -92,6 +102,10 @@
<version>
${jetty.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
...
...
spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java
0 → 100644
View file @
f3aa236e
/*
* Copyright 2012-2016 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
.
devtools
.
autoconfigure
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.Set
;
import
javax.sql.DataSource
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabase
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for DevTools-specific
* {@link DataSource} configuration.
*
* @author Andy Wilkinson
* @since 1.3.3
*/
@AutoConfigureAfter
(
DataSourceAutoConfiguration
.
class
)
@ConditionalOnBean
({
DataSource
.
class
,
DataSourceProperties
.
class
})
@Configuration
public
class
DevToolsDataSourceAutoConfiguration
{
@Bean
NonEmbeddedInMemoryDatabaseShutdownExecutor
inMemoryDatabaseShutdownExecutor
(
DataSource
dataSource
,
DataSourceProperties
dataSourceProperties
)
{
return
new
NonEmbeddedInMemoryDatabaseShutdownExecutor
(
dataSource
,
dataSourceProperties
);
}
static
final
class
NonEmbeddedInMemoryDatabaseShutdownExecutor
implements
DisposableBean
{
private
static
final
Set
<
String
>
IN_MEMORY_DRIVER_CLASS_NAMES
=
new
HashSet
<
String
>(
Arrays
.
asList
(
"org.apache.derby.jdbc.EmbeddedDriver"
,
"org.h2.Driver"
,
"org.h2.jdbcx.JdbcDataSource"
,
"org.hsqldb.jdbcDriver"
,
"org.hsqldb.jdbc.JDBCDriver"
,
"org.hsqldb.jdbc.pool.JDBCXADataSource"
));
private
final
DataSource
dataSource
;
private
final
DataSourceProperties
dataSourceProperties
;
public
NonEmbeddedInMemoryDatabaseShutdownExecutor
(
DataSource
dataSource
,
DataSourceProperties
dataSourceProperties
)
{
this
.
dataSource
=
dataSource
;
this
.
dataSourceProperties
=
dataSourceProperties
;
}
@Override
public
void
destroy
()
throws
Exception
{
if
(
dataSourceRequiresShutdown
())
{
this
.
dataSource
.
getConnection
().
createStatement
().
execute
(
"SHUTDOWN"
);
}
}
private
boolean
dataSourceRequiresShutdown
()
{
return
IN_MEMORY_DRIVER_CLASS_NAMES
.
contains
(
this
.
dataSourceProperties
.
getDriverClassName
())
&&
(!(
this
.
dataSource
instanceof
EmbeddedDatabase
));
}
}
}
spring-boot-devtools/src/main/resources/META-INF/spring.factories
View file @
f3aa236e
...
...
@@ -8,6 +8,7 @@ org.springframework.boot.devtools.restart.RestartApplicationListener
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration,\
org.springframework.boot.devtools.autoconfigure.LocalDevToolsAutoConfiguration,\
org.springframework.boot.devtools.autoconfigure.RemoteDevToolsAutoConfiguration
...
...
spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfigurationTests.java
0 → 100644
View file @
f3aa236e
/*
* Copyright 2012-2016 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
.
devtools
.
autoconfigure
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
javax.sql.DataSource
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabase
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Tests for {@link DevToolsDataSourceAutoConfiguration}.
*
* @author Andy Wilkinson
*/
public
class
DevToolsDataSourceAutoConfigurationTests
{
@Test
public
void
embeddedDatabaseIsNotShutDown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.h2.Driver"
,
EmbeddedDatabaseConfiguration
.
class
);
DataSource
dataSource
=
context
.
getBean
(
DataSource
.
class
);
context
.
close
();
verify
(
dataSource
,
times
(
0
)).
getConnection
();
}
@Test
public
void
externalDatabaseIsNotShutDown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.postgresql.Driver"
,
DataSourceConfiguration
.
class
);
DataSource
dataSource
=
context
.
getBean
(
DataSource
.
class
);
context
.
close
();
verify
(
dataSource
,
times
(
0
)).
getConnection
();
}
@Test
public
void
nonEmbeddedInMemoryDatabaseIsShutDown
()
throws
SQLException
{
ConfigurableApplicationContext
context
=
createContext
(
"org.h2.Driver"
,
DataSourceConfiguration
.
class
);
DataSource
dataSource
=
context
.
getBean
(
DataSource
.
class
);
Connection
connection
=
mock
(
Connection
.
class
);
given
(
dataSource
.
getConnection
()).
willReturn
(
connection
);
Statement
statement
=
mock
(
Statement
.
class
);
given
(
connection
.
createStatement
()).
willReturn
(
statement
);
context
.
close
();
verify
(
statement
).
execute
(
"SHUTDOWN"
);
}
private
ConfigurableApplicationContext
createContext
(
String
driver
,
Class
<?>...
classes
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
classes
);
context
.
register
(
DevToolsDataSourceAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
context
,
"spring.datasource.driver-class-name:"
+
driver
);
context
.
refresh
();
return
context
;
}
@Configuration
@EnableConfigurationProperties
(
DataSourceProperties
.
class
)
static
class
EmbeddedDatabaseConfiguration
{
@Bean
public
EmbeddedDatabase
embeddedDatabase
()
{
return
mock
(
EmbeddedDatabase
.
class
);
}
}
@Configuration
@EnableConfigurationProperties
(
DataSourceProperties
.
class
)
static
class
DataSourceConfiguration
{
@Bean
public
DataSource
in
()
{
return
mock
(
DataSource
.
class
);
}
}
}
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