001/* 002 * Copyright 2013 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.batch.core.configuration.annotation; 017 018import org.springframework.context.annotation.Scope; 019import org.springframework.context.annotation.ScopedProxyMode; 020 021import java.lang.annotation.Documented; 022import java.lang.annotation.Retention; 023import java.lang.annotation.RetentionPolicy; 024 025/** 026 * <p> 027 * Convenient annotation for job scoped beans that defaults the proxy mode, so that it doesn't have to be specified 028 * explicitly on every bean definition. Use this on any @Bean that needs to inject @Values from the job 029 * context, and any bean that needs to share a lifecycle with a job execution (e.g. an JobExecutionListener). E.g. 030 * </p> 031 * 032 * <pre class="code"> 033 * @Bean 034 * @JobScope 035 * protected Callable<String> value(@Value("#{jobExecution.jobInstance.jobName}") 036 * final String value) { 037 * return new SimpleCallable(value); 038 * } 039 * </pre> 040 * 041 * <p>Marking a @Bean as @JobScope is equivalent to marking it as <code>@Scope(value="job", proxyMode=TARGET_CLASS)</code></p> 042 * 043 * @author Michael Minella 044 * 045 * @since 3.0.1 046 * 047 */ 048@Scope(value = "job", proxyMode = ScopedProxyMode.TARGET_CLASS) 049@Retention(RetentionPolicy.RUNTIME) 050@Documented 051public @interface JobScope { 052 053}