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 */ 016 017package org.springframework.batch.core.scope.context; 018 019import org.aspectj.lang.annotation.Around; 020import org.aspectj.lang.annotation.Aspect; 021import org.springframework.batch.core.Job; 022import org.springframework.batch.core.JobExecution; 023 024/** 025 * Convenient aspect to wrap a single threaded job execution, where the 026 * implementation of the {@link Job} is not job scope aware (i.e. not the ones 027 * provided by the framework). 028 * 029 * @author Dave Syer 030 * @author Jimmy Praet 031 * @since 3.0 032 */ 033@Aspect 034public class JobScopeManager { 035 036 @Around("execution(void org.springframework.batch.core.Job+.execute(*)) && target(job) && args(jobExecution)") 037 public void execute(Job job, JobExecution jobExecution) { 038 JobSynchronizationManager.register(jobExecution); 039 try { 040 job.execute(jobExecution); 041 } 042 finally { 043 JobSynchronizationManager.release(); 044 } 045 } 046 047}