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
7f420d12
Commit
7f420d12
authored
Jun 06, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-9411
parent
db060c84
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
90 deletions
+31
-90
QuartzAutoConfiguration.java
...rk/boot/autoconfigure/quartz/QuartzAutoConfiguration.java
+21
-17
SchedulerDependsOnPostProcessor.java
...autoconfigure/quartz/SchedulerDependsOnPostProcessor.java
+0
-41
QuartzAutoConfigurationTests.java
...ot/autoconfigure/quartz/QuartzAutoConfigurationTests.java
+9
-6
pom.xml
spring-boot-samples/spring-boot-sample-quartz/pom.xml
+0
-8
SampleQuartzApplication.java
.../src/main/java/sample/quartz/SampleQuartzApplication.java
+1
-16
application.properties
...t-sample-quartz/src/main/resources/application.properties
+0
-2
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java
View file @
7f420d12
...
@@ -29,11 +29,11 @@ import org.quartz.Scheduler;
...
@@ -29,11 +29,11 @@ import org.quartz.Scheduler;
import
org.quartz.Trigger
;
import
org.quartz.Trigger
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
;
import
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
;
...
@@ -130,12 +130,22 @@ public class QuartzAutoConfiguration {
...
@@ -130,12 +130,22 @@ public class QuartzAutoConfiguration {
@Configuration
@Configuration
@ConditionalOnSingleCandidate
(
DataSource
.
class
)
@ConditionalOnSingleCandidate
(
DataSource
.
class
)
@ConditionalOnProperty
(
prefix
=
"spring.quartz"
,
name
=
"job-store-type"
,
havingValue
=
"jdbc"
)
protected
static
class
JdbcStoreTypeConfiguration
{
protected
static
class
JdbcStoreTypeConfiguration
{
@Bean
@Bean
public
static
InitializerSchedulerDependencyPostProcessor
initializerSchedulerDependencyPostProcessor
()
{
public
SchedulerFactoryBeanCustomizer
dataSourceCustomizer
(
return
new
InitializerSchedulerDependencyPostProcessor
();
QuartzProperties
properties
,
DataSource
dataSource
,
ObjectProvider
<
PlatformTransactionManager
>
transactionManager
)
{
return
schedulerFactoryBean
->
{
if
(
properties
.
getJobStoreType
()
==
JobStoreType
.
JDBC
)
{
schedulerFactoryBean
.
setDataSource
(
dataSource
);
PlatformTransactionManager
txManager
=
transactionManager
.
getIfUnique
();
if
(
txManager
!=
null
)
{
schedulerFactoryBean
.
setTransactionManager
(
txManager
);
}
}
};
}
}
@Bean
@Bean
...
@@ -146,22 +156,16 @@ public class QuartzAutoConfiguration {
...
@@ -146,22 +156,16 @@ public class QuartzAutoConfiguration {
}
}
@Bean
@Bean
public
SchedulerFactoryBeanCustomizer
dataSourceCustomizer
(
DataSource
dataSource
,
public
static
DatabaseInitializerSchedulerDependencyPostProcessor
databaseInitializerSchedulerDependencyPostProcessor
()
{
ObjectProvider
<
PlatformTransactionManager
>
transactionManager
)
{
return
new
DatabaseInitializerSchedulerDependencyPostProcessor
();
return
schedulerFactoryBean
->
{
schedulerFactoryBean
.
setDataSource
(
dataSource
);
PlatformTransactionManager
txManager
=
transactionManager
.
getIfUnique
();
if
(
txManager
!=
null
)
{
schedulerFactoryBean
.
setTransactionManager
(
txManager
);
}
};
}
}
private
static
class
InitializerSchedulerDependencyPostProcessor
private
static
class
Database
InitializerSchedulerDependencyPostProcessor
extends
SchedulerDependsOn
PostProcessor
{
extends
AbstractDependsOnBeanFactory
PostProcessor
{
InitializerSchedulerDependencyPostProcessor
()
{
DatabaseInitializerSchedulerDependencyPostProcessor
()
{
super
(
"quartzDatabaseInitializer"
);
super
(
Scheduler
.
class
,
SchedulerFactoryBean
.
class
,
"quartzDatabaseInitializer"
);
}
}
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/SchedulerDependsOnPostProcessor.java
deleted
100644 → 0
View file @
db060c84
/*
* 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
.
quartz
;
import
org.quartz.Scheduler
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor
;
import
org.springframework.scheduling.quartz.SchedulerFactoryBean
;
/**
* {@link BeanFactoryPostProcessor} that can be used to dynamically declare that all
* {@link Scheduler} beans should "depend on" one or more specific beans.
*
* @author Vedran Pavic
* @since 2.0.0
* @see BeanDefinition#setDependsOn(String[])
*/
public
class
SchedulerDependsOnPostProcessor
extends
AbstractDependsOnBeanFactoryPostProcessor
{
public
SchedulerDependsOnPostProcessor
(
String
...
dependsOn
)
{
super
(
Scheduler
.
class
,
SchedulerFactoryBean
.
class
,
dependsOn
);
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java
View file @
7f420d12
...
@@ -50,11 +50,13 @@ import org.springframework.context.ConfigurableApplicationContext;
...
@@ -50,11 +50,13 @@ import org.springframework.context.ConfigurableApplicationContext;
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.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.scheduling.quartz.LocalDataSourceJobStore
;
import
org.springframework.scheduling.quartz.LocalDataSourceJobStore
;
import
org.springframework.scheduling.quartz.LocalTaskExecutorThreadPool
;
import
org.springframework.scheduling.quartz.LocalTaskExecutorThreadPool
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -199,13 +201,10 @@ public class QuartzAutoConfigurationTests {
...
@@ -199,13 +201,10 @@ public class QuartzAutoConfigurationTests {
this
.
context
=
ctx
;
this
.
context
=
ctx
;
}
}
@Import
(
ComponentThatUsesScheduler
.
class
)
@Configuration
protected
static
class
BaseQuartzConfiguration
{
protected
static
class
BaseQuartzConfiguration
{
@Bean
public
ComponentThatUsesScheduler
component
()
{
return
new
ComponentThatUsesScheduler
();
}
}
}
@Configuration
@Configuration
...
@@ -283,9 +282,13 @@ public class QuartzAutoConfigurationTests {
...
@@ -283,9 +282,13 @@ public class QuartzAutoConfigurationTests {
public
static
class
ComponentThatUsesScheduler
{
public
static
class
ComponentThatUsesScheduler
{
@Autowired
private
Scheduler
scheduler
;
private
Scheduler
scheduler
;
public
ComponentThatUsesScheduler
(
Scheduler
scheduler
)
{
Assert
.
notNull
(
scheduler
,
"Scheduler must not be null"
);
this
.
scheduler
=
scheduler
;
}
}
}
public
static
class
FooJob
extends
QuartzJobBean
{
public
static
class
FooJob
extends
QuartzJobBean
{
...
...
spring-boot-samples/spring-boot-sample-quartz/pom.xml
View file @
7f420d12
...
@@ -23,14 +23,6 @@
...
@@ -23,14 +23,6 @@
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-quartz
</artifactId>
<artifactId>
spring-boot-starter-quartz
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java
View file @
7f420d12
...
@@ -18,36 +18,21 @@ package sample.quartz;
...
@@ -18,36 +18,21 @@ package sample.quartz;
import
org.quartz.JobBuilder
;
import
org.quartz.JobBuilder
;
import
org.quartz.JobDetail
;
import
org.quartz.JobDetail
;
import
org.quartz.Scheduler
;
import
org.quartz.SimpleScheduleBuilder
;
import
org.quartz.SimpleScheduleBuilder
;
import
org.quartz.Trigger
;
import
org.quartz.Trigger
;
import
org.quartz.TriggerBuilder
;
import
org.quartz.TriggerBuilder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
@SpringBootApplication
@SpringBootApplication
public
class
SampleQuartzApplication
implements
CommandLineRunner
{
public
class
SampleQuartzApplication
{
@Autowired
private
Scheduler
scheduler
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SampleQuartzApplication
.
class
,
args
);
SpringApplication
.
run
(
SampleQuartzApplication
.
class
,
args
);
}
}
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
Trigger
trigger
=
TriggerBuilder
.
newTrigger
().
forJob
(
sampleJobDetail
())
.
withIdentity
(
"startTrigger"
).
usingJobData
(
"name"
,
"Boot"
).
startNow
()
.
build
();
this
.
scheduler
.
scheduleJob
(
trigger
);
}
@Bean
@Bean
public
JobDetail
sampleJobDetail
()
{
public
JobDetail
sampleJobDetail
()
{
return
JobBuilder
.
newJob
(
SampleJob
.
class
).
withIdentity
(
"sampleJob"
)
return
JobBuilder
.
newJob
(
SampleJob
.
class
).
withIdentity
(
"sampleJob"
)
...
...
spring-boot-samples/spring-boot-sample-quartz/src/main/resources/application.properties
deleted
100644 → 0
View file @
db060c84
spring.quartz.job-store-type
=
jdbc
spring.quartz.jdbc.initialize-schema
=
true
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