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
2f5ab503
Commit
2f5ab503
authored
Apr 05, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add @QuartzDataSource for quartz auto-configuration
Closes gh-12755
parent
5587eac8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
3 deletions
+80
-3
QuartzAutoConfiguration.java
...rk/boot/autoconfigure/quartz/QuartzAutoConfiguration.java
+13
-3
QuartzDataSource.java
...framework/boot/autoconfigure/quartz/QuartzDataSource.java
+40
-0
QuartzAutoConfigurationTests.java
...ot/autoconfigure/quartz/QuartzAutoConfigurationTests.java
+27
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java
View file @
2f5ab503
...
@@ -135,10 +135,12 @@ public class QuartzAutoConfiguration {
...
@@ -135,10 +135,12 @@ public class QuartzAutoConfiguration {
@Bean
@Bean
public
SchedulerFactoryBeanCustomizer
dataSourceCustomizer
(
public
SchedulerFactoryBeanCustomizer
dataSourceCustomizer
(
QuartzProperties
properties
,
DataSource
dataSource
,
QuartzProperties
properties
,
DataSource
dataSource
,
@QuartzDataSource
ObjectProvider
<
DataSource
>
quartzDataSource
,
ObjectProvider
<
PlatformTransactionManager
>
transactionManager
)
{
ObjectProvider
<
PlatformTransactionManager
>
transactionManager
)
{
return
(
schedulerFactoryBean
)
->
{
return
(
schedulerFactoryBean
)
->
{
if
(
properties
.
getJobStoreType
()
==
JobStoreType
.
JDBC
)
{
if
(
properties
.
getJobStoreType
()
==
JobStoreType
.
JDBC
)
{
schedulerFactoryBean
.
setDataSource
(
dataSource
);
DataSource
dataSourceToUse
=
getDataSource
(
dataSource
,
quartzDataSource
);
schedulerFactoryBean
.
setDataSource
(
dataSourceToUse
);
PlatformTransactionManager
txManager
=
transactionManager
PlatformTransactionManager
txManager
=
transactionManager
.
getIfUnique
();
.
getIfUnique
();
if
(
txManager
!=
null
)
{
if
(
txManager
!=
null
)
{
...
@@ -148,12 +150,20 @@ public class QuartzAutoConfiguration {
...
@@ -148,12 +150,20 @@ public class QuartzAutoConfiguration {
};
};
}
}
private
DataSource
getDataSource
(
DataSource
dataSource
,
@QuartzDataSource
ObjectProvider
<
DataSource
>
quartzDataSource
)
{
DataSource
dataSourceIfAvailable
=
quartzDataSource
.
getIfAvailable
();
return
(
dataSourceIfAvailable
!=
null
?
dataSourceIfAvailable
:
dataSource
);
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
QuartzDataSourceInitializer
quartzDataSourceInitializer
(
public
QuartzDataSourceInitializer
quartzDataSourceInitializer
(
DataSource
dataSource
,
ResourceLoader
resourceLoader
,
DataSource
dataSource
,
@QuartzDataSource
ObjectProvider
<
DataSource
>
quartzDataSource
,
ResourceLoader
resourceLoader
,
QuartzProperties
properties
)
{
QuartzProperties
properties
)
{
return
new
QuartzDataSourceInitializer
(
dataSource
,
resourceLoader
,
DataSource
dataSourceToUse
=
getDataSource
(
dataSource
,
quartzDataSource
);
return
new
QuartzDataSourceInitializer
(
dataSourceToUse
,
resourceLoader
,
properties
);
properties
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSource.java
0 → 100644
View file @
2f5ab503
/*
* Copyright 2012-2018 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
.
quartz
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.springframework.beans.factory.annotation.Qualifier
;
/**
* Qualifier annotation for a DataSource to be injected into Quartz auto-configuration. Can be used on
* a secondary data source, if there is another one marked as {@code @Primary}.
*
* @author Madhura Bhave
* @since 2.0.2
*/
@Target
({
ElementType
.
FIELD
,
ElementType
.
METHOD
,
ElementType
.
PARAMETER
,
ElementType
.
TYPE
,
ElementType
.
ANNOTATION_TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Qualifier
public
@interface
QuartzDataSource
{
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java
View file @
2f5ab503
...
@@ -21,6 +21,7 @@ import java.util.concurrent.Executors;
...
@@ -21,6 +21,7 @@ import java.util.concurrent.Executors;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
com.zaxxer.hikari.HikariDataSource
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -43,6 +44,7 @@ import org.quartz.simpl.SimpleThreadPool;
...
@@ -43,6 +44,7 @@ import org.quartz.simpl.SimpleThreadPool;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration
;
import
org.springframework.boot.jdbc.DataSourceBuilder
;
import
org.springframework.boot.test.rule.OutputCapture
;
import
org.springframework.boot.test.rule.OutputCapture
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
@@ -207,6 +209,12 @@ public class QuartzAutoConfigurationTests {
...
@@ -207,6 +209,12 @@ public class QuartzAutoConfigurationTests {
assertThat
(
scheduler
.
getSchedulerName
()).
isEqualTo
(
"fooScheduler"
);
assertThat
(
scheduler
.
getSchedulerName
()).
isEqualTo
(
"fooScheduler"
);
}
}
@Test
public
void
dataSourceWithQuartzDataSourceQualifierUsedWhenMultiplePresent
()
{
load
(
MultipleDataSourceConfiguration
.
class
,
"spring.quartz.job-store-type=jdbc"
);
}
private
void
load
(
String
...
environment
)
{
private
void
load
(
String
...
environment
)
{
load
(
new
Class
<?>[
0
],
environment
);
load
(
new
Class
<?>[
0
],
environment
);
}
}
...
@@ -345,6 +353,25 @@ public class QuartzAutoConfigurationTests {
...
@@ -345,6 +353,25 @@ public class QuartzAutoConfigurationTests {
}
}
@Configuration
protected
static
class
MultipleDataSourceConfiguration
extends
BaseQuartzConfiguration
{
@Bean
@Primary
public
DataSource
applicationDataSource
()
{
return
new
HikariDataSource
();
}
@QuartzDataSource
@Bean
public
DataSource
quartzDataSource
()
{
return
DataSourceBuilder
.
create
().
url
(
"jdbc:hsqldb:mem:quartztest"
)
.
username
(
"sa"
).
build
();
}
}
public
static
class
ComponentThatUsesScheduler
{
public
static
class
ComponentThatUsesScheduler
{
public
ComponentThatUsesScheduler
(
Scheduler
scheduler
)
{
public
ComponentThatUsesScheduler
(
Scheduler
scheduler
)
{
...
...
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