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
b0626bca
Commit
b0626bca
authored
Jul 08, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-17454
parents
5b7c0e0c
02bea782
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
19 deletions
+107
-19
BatchAutoConfiguration.java
...work/boot/autoconfigure/batch/BatchAutoConfiguration.java
+20
-19
BatchAutoConfigurationWithoutJdbcTests.java
...nfigure/batch/BatchAutoConfigurationWithoutJdbcTests.java
+87
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java
View file @
b0626bca
...
...
@@ -39,7 +39,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.jdbc.
core.JdbcOperations
;
import
org.springframework.jdbc.
datasource.init.DatabasePopulator
;
import
org.springframework.util.StringUtils
;
/**
...
...
@@ -60,35 +60,20 @@ import org.springframework.util.StringUtils;
* @since 1.0.0
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
JobLauncher
.
class
,
DataSource
.
class
,
JdbcOperations
.
class
})
@ConditionalOnClass
({
JobLauncher
.
class
,
DataSource
.
class
})
@AutoConfigureAfter
(
HibernateJpaAutoConfiguration
.
class
)
@ConditionalOnBean
(
JobLauncher
.
class
)
@EnableConfigurationProperties
(
BatchProperties
.
class
)
@Import
(
BatchConfigurerConfiguration
.
class
)
public
class
BatchAutoConfiguration
{
private
final
BatchProperties
properties
;
public
BatchAutoConfiguration
(
BatchProperties
properties
)
{
this
.
properties
=
properties
;
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
DataSource
.
class
)
public
BatchDataSourceInitializer
batchDataSourceInitializer
(
DataSource
dataSource
,
@BatchDataSource
ObjectProvider
<
DataSource
>
batchDataSource
,
ResourceLoader
resourceLoader
)
{
return
new
BatchDataSourceInitializer
(
batchDataSource
.
getIfAvailable
(()
->
dataSource
),
resourceLoader
,
this
.
properties
);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty
(
prefix
=
"spring.batch.job"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
JobLauncherCommandLineRunner
jobLauncherCommandLineRunner
(
JobLauncher
jobLauncher
,
JobExplorer
jobExplorer
,
JobRepository
jobRepository
)
{
JobRepository
jobRepository
,
BatchProperties
properties
)
{
JobLauncherCommandLineRunner
runner
=
new
JobLauncherCommandLineRunner
(
jobLauncher
,
jobExplorer
,
jobRepository
);
String
jobNames
=
this
.
properties
.
getJob
().
getNames
();
String
jobNames
=
properties
.
getJob
().
getNames
();
if
(
StringUtils
.
hasText
(
jobNames
))
{
runner
.
setJobNames
(
jobNames
);
}
...
...
@@ -115,4 +100,20 @@ public class BatchAutoConfiguration {
return
factory
;
}
@ConditionalOnBean
(
DataSource
.
class
)
@ConditionalOnClass
(
DatabasePopulator
.
class
)
static
class
DataSourceInitializerConfiguration
{
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
DataSource
.
class
)
BatchDataSourceInitializer
batchDataSourceInitializer
(
DataSource
dataSource
,
@BatchDataSource
ObjectProvider
<
DataSource
>
batchDataSource
,
ResourceLoader
resourceLoader
,
BatchProperties
properties
)
{
return
new
BatchDataSourceInitializer
(
batchDataSource
.
getIfAvailable
(()
->
dataSource
),
resourceLoader
,
properties
);
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJdbcTests.java
0 → 100644
View file @
b0626bca
/*
* Copyright 2012-2019 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
*
* https://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
.
batch
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.batch.core.configuration.annotation.BatchConfigurer
;
import
org.springframework.batch.core.configuration.annotation.EnableBatchProcessing
;
import
org.springframework.batch.core.explore.JobExplorer
;
import
org.springframework.batch.core.launch.JobLauncher
;
import
org.springframework.batch.core.launch.support.SimpleJobOperator
;
import
org.springframework.batch.core.repository.JobRepository
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
;
import
org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link BatchAutoConfiguration} when Spring JDBC is not on the classpath.
*
* @author Andy Wilkinson
*/
@RunWith
(
ModifiedClassPathRunner
.
class
)
@ClassPathExclusions
(
"spring-jdbc-*.jar"
)
class
BatchAutoConfigurationWithoutJdbcTests
{
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
BatchAutoConfiguration
.
class
,
TransactionAutoConfiguration
.
class
))
.
withUserConfiguration
(
BatchConfiguration
.
class
);
@Test
void
whenThereIsNoJdbcOnTheClasspathThenComponentsAreStillAutoConfigured
()
{
this
.
contextRunner
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
JobLauncherCommandLineRunner
.
class
);
assertThat
(
context
).
hasSingleBean
(
JobExecutionExitCodeGenerator
.
class
);
assertThat
(
context
).
hasSingleBean
(
SimpleJobOperator
.
class
);
});
}
@Configuration
@EnableBatchProcessing
static
class
BatchConfiguration
implements
BatchConfigurer
{
@Override
public
JobRepository
getJobRepository
()
throws
Exception
{
return
mock
(
JobRepository
.
class
);
}
@Override
public
PlatformTransactionManager
getTransactionManager
()
throws
Exception
{
return
mock
(
PlatformTransactionManager
.
class
);
}
@Override
public
JobLauncher
getJobLauncher
()
throws
Exception
{
return
mock
(
JobLauncher
.
class
);
}
@Override
public
JobExplorer
getJobExplorer
()
throws
Exception
{
return
mock
(
JobExplorer
.
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