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
ded90209
Commit
ded90209
authored
Nov 19, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow Batch datbase initializer to be disabled
parent
caffc28b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
18 deletions
+62
-18
BatchDatabaseInitializer.java
...rk/boot/autoconfigure/batch/BatchDatabaseInitializer.java
+20
-14
AbstractRepositoryConfigurationSourceSupport.java
...re/data/AbstractRepositoryConfigurationSourceSupport.java
+1
-1
EmbeddedDataSourceConfiguration.java
...t/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java
+5
-1
BatchAutoConfigurationTests.java
...boot/autoconfigure/batch/BatchAutoConfigurationTests.java
+36
-2
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchDatabaseInitializer.java
View file @
ded90209
...
@@ -21,6 +21,7 @@ import javax.sql.DataSource;
...
@@ -21,6 +21,7 @@ import javax.sql.DataSource;
import
org.springframework.batch.support.DatabaseType
;
import
org.springframework.batch.support.DatabaseType
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
...
@@ -45,6 +46,9 @@ public class BatchDatabaseInitializer implements EnvironmentAware {
...
@@ -45,6 +46,9 @@ public class BatchDatabaseInitializer implements EnvironmentAware {
@Autowired
@Autowired
private
ResourceLoader
resourceLoader
;
private
ResourceLoader
resourceLoader
;
@Value
(
"${spring.batch.initializer.enabled:true}"
)
private
boolean
enabled
=
true
;
private
RelaxedPropertyResolver
environment
;
private
RelaxedPropertyResolver
environment
;
@Override
@Override
...
@@ -54,20 +58,22 @@ public class BatchDatabaseInitializer implements EnvironmentAware {
...
@@ -54,20 +58,22 @@ public class BatchDatabaseInitializer implements EnvironmentAware {
@PostConstruct
@PostConstruct
protected
void
initialize
()
throws
Exception
{
protected
void
initialize
()
throws
Exception
{
String
platform
=
DatabaseType
.
fromMetaData
(
this
.
dataSource
).
toString
()
if
(
this
.
enabled
)
{
.
toLowerCase
();
String
platform
=
DatabaseType
.
fromMetaData
(
this
.
dataSource
).
toString
()
if
(
"hsql"
.
equals
(
platform
))
{
.
toLowerCase
();
platform
=
"hsqldb"
;
if
(
"hsql"
.
equals
(
platform
))
{
}
platform
=
"hsqldb"
;
if
(
"postgres"
.
equals
(
platform
))
{
}
platform
=
"postgresql"
;
if
(
"postgres"
.
equals
(
platform
))
{
platform
=
"postgresql"
;
}
ResourceDatabasePopulator
populator
=
new
ResourceDatabasePopulator
();
String
schemaLocation
=
this
.
environment
.
getProperty
(
"schema"
,
DEFAULT_SCHEMA_LOCATION
);
schemaLocation
=
schemaLocation
.
replace
(
"@@platform@@"
,
platform
);
populator
.
addScript
(
this
.
resourceLoader
.
getResource
(
schemaLocation
));
populator
.
setContinueOnError
(
true
);
DatabasePopulatorUtils
.
execute
(
populator
,
this
.
dataSource
);
}
}
ResourceDatabasePopulator
populator
=
new
ResourceDatabasePopulator
();
String
schemaLocation
=
this
.
environment
.
getProperty
(
"schema"
,
DEFAULT_SCHEMA_LOCATION
);
schemaLocation
=
schemaLocation
.
replace
(
"@@platform@@"
,
platform
);
populator
.
addScript
(
this
.
resourceLoader
.
getResource
(
schemaLocation
));
populator
.
setContinueOnError
(
true
);
DatabasePopulatorUtils
.
execute
(
populator
,
this
.
dataSource
);
}
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/AbstractRepositoryConfigurationSourceSupport.java
View file @
ded90209
...
@@ -111,7 +111,7 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements
...
@@ -111,7 +111,7 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements
List
<
String
>
basePackages
=
AutoConfigurationUtils
List
<
String
>
basePackages
=
AutoConfigurationUtils
.
getBasePackages
(
this
.
beanFactory
);
.
getBasePackages
(
this
.
beanFactory
);
if
(
basePackages
.
isEmpty
())
{
if
(
basePackages
.
isEmpty
())
{
logger
.
warn
(
"Unable to find repository base packages. If you need Repositories please define "
logger
.
info
(
"Unable to find repository base packages. If you need Repositories please define "
+
"a @ComponentScan annotation or else disable *RepositoriesAutoConfiguration"
);
+
"a @ComponentScan annotation or else disable *RepositoriesAutoConfiguration"
);
}
}
return
basePackages
;
return
basePackages
;
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java
View file @
ded90209
...
@@ -20,6 +20,7 @@ import javax.annotation.PreDestroy;
...
@@ -20,6 +20,7 @@ import javax.annotation.PreDestroy;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
org.springframework.beans.factory.BeanClassLoaderAware
;
import
org.springframework.beans.factory.BeanClassLoaderAware
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabase
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabase
;
...
@@ -38,6 +39,9 @@ public class EmbeddedDataSourceConfiguration implements BeanClassLoaderAware {
...
@@ -38,6 +39,9 @@ public class EmbeddedDataSourceConfiguration implements BeanClassLoaderAware {
private
ClassLoader
classLoader
;
private
ClassLoader
classLoader
;
@Value
(
"${spring.datasource.name:testdb}"
)
private
String
name
=
"testdb"
;
@Override
@Override
public
void
setBeanClassLoader
(
ClassLoader
classLoader
)
{
public
void
setBeanClassLoader
(
ClassLoader
classLoader
)
{
this
.
classLoader
=
classLoader
;
this
.
classLoader
=
classLoader
;
...
@@ -47,7 +51,7 @@ public class EmbeddedDataSourceConfiguration implements BeanClassLoaderAware {
...
@@ -47,7 +51,7 @@ public class EmbeddedDataSourceConfiguration implements BeanClassLoaderAware {
public
DataSource
dataSource
()
{
public
DataSource
dataSource
()
{
EmbeddedDatabaseBuilder
builder
=
new
EmbeddedDatabaseBuilder
()
EmbeddedDatabaseBuilder
builder
=
new
EmbeddedDatabaseBuilder
()
.
setType
(
EmbeddedDatabaseConnection
.
get
(
this
.
classLoader
).
getType
());
.
setType
(
EmbeddedDatabaseConnection
.
get
(
this
.
classLoader
).
getType
());
this
.
database
=
builder
.
build
();
this
.
database
=
builder
.
setName
(
this
.
name
).
build
();
return
this
.
database
;
return
this
.
database
;
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java
View file @
ded90209
...
@@ -19,7 +19,12 @@ package org.springframework.boot.autoconfigure.batch;
...
@@ -19,7 +19,12 @@ package org.springframework.boot.autoconfigure.batch;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
javax.sql.DataSource
;
import
org.junit.After
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.batch.core.BatchStatus
;
import
org.springframework.batch.core.BatchStatus
;
import
org.springframework.batch.core.Job
;
import
org.springframework.batch.core.Job
;
import
org.springframework.batch.core.JobExecution
;
import
org.springframework.batch.core.JobExecution
;
...
@@ -31,13 +36,15 @@ import org.springframework.batch.core.job.AbstractJob;
...
@@ -31,13 +36,15 @@ import org.springframework.batch.core.job.AbstractJob;
import
org.springframework.batch.core.launch.JobLauncher
;
import
org.springframework.batch.core.launch.JobLauncher
;
import
org.springframework.batch.core.repository.JobRepository
;
import
org.springframework.batch.core.repository.JobRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.TestUtils
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration
;
import
org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.jdbc.BadSqlGrammarException
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
/**
/**
...
@@ -49,6 +56,16 @@ public class BatchAutoConfigurationTests {
...
@@ -49,6 +56,16 @@ public class BatchAutoConfigurationTests {
private
AnnotationConfigApplicationContext
context
;
private
AnnotationConfigApplicationContext
context
;
@Rule
public
ExpectedException
expected
=
ExpectedException
.
none
();
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
@Test
public
void
testDefaultContext
()
throws
Exception
{
public
void
testDefaultContext
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
...
@@ -57,6 +74,8 @@ public class BatchAutoConfigurationTests {
...
@@ -57,6 +74,8 @@ public class BatchAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration
.
class
);
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
assertNotNull
(
this
.
context
.
getBean
(
JobLauncher
.
class
));
assertNotNull
(
this
.
context
.
getBean
(
JobLauncher
.
class
));
assertEquals
(
0
,
new
JdbcTemplate
(
this
.
context
.
getBean
(
DataSource
.
class
))
.
queryForList
(
"select * from BATCH_JOB_EXECUTION"
).
size
());
}
}
@Test
@Test
...
@@ -72,6 +91,21 @@ public class BatchAutoConfigurationTests {
...
@@ -72,6 +91,21 @@ public class BatchAutoConfigurationTests {
"job"
,
new
JobParameters
()));
"job"
,
new
JobParameters
()));
}
}
@Test
public
void
testDisableSchemaLoader
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestUtils
.
addEnviroment
(
this
.
context
,
"spring.datasource.name:batchtest"
,
"spring.batch.initializer.enabled:false"
);
this
.
context
.
register
(
TestConfiguration
.
class
,
BatchAutoConfiguration
.
class
,
EmbeddedDataSourceConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertNotNull
(
this
.
context
.
getBean
(
JobLauncher
.
class
));
this
.
expected
.
expect
(
BadSqlGrammarException
.
class
);
new
JdbcTemplate
(
this
.
context
.
getBean
(
DataSource
.
class
))
.
queryForList
(
"select * from BATCH_JOB_EXECUTION"
);
}
@EnableBatchProcessing
@EnableBatchProcessing
protected
static
class
TestConfiguration
{
protected
static
class
TestConfiguration
{
}
}
...
...
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