org.springframework.batch.core.configuration.annotation.JobScope Maven / Gradle / Ivy
/*
* Copyright 2013 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.batch.core.configuration.annotation;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
*
* Convenient annotation for job scoped beans that defaults the proxy mode, so that it doesn't have to be specified
* explicitly on every bean definition. Use this on any @Bean that needs to inject @Values from the job
* context, and any bean that needs to share a lifecycle with a job execution (e.g. an JobExecutionListener). E.g.
*
*
*
* @Bean
* @JobScope
* protected Callable<String> value(@Value("#{jobExecution.jobInstance.jobName}")
* final String value) {
* return new SimpleCallable(value);
* }
*
*
* Marking a @Bean as @JobScope is equivalent to marking it as @Scope(value="job", proxyMode=TARGET_CLASS)
*
* @author Michael Minella
*
* @since 3.0.1
*
*/
@Scope(value = "job", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface JobScope {
}