001/* 002 * Copyright 2002-2015 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.aop.aspectj.annotation; 018 019import java.io.Serializable; 020 021import org.springframework.beans.factory.BeanFactory; 022 023/** 024 * {@link org.springframework.aop.aspectj.AspectInstanceFactory} backed by a 025 * {@link BeanFactory}-provided prototype, enforcing prototype semantics. 026 * 027 * <p>Note that this may instantiate multiple times, which probably won't give the 028 * semantics you expect. Use a {@link LazySingletonAspectInstanceFactoryDecorator} 029 * to wrap this to ensure only one new aspect comes back. 030 * 031 * @author Rod Johnson 032 * @author Juergen Hoeller 033 * @since 2.0 034 * @see org.springframework.beans.factory.BeanFactory 035 * @see LazySingletonAspectInstanceFactoryDecorator 036 */ 037@SuppressWarnings("serial") 038public class PrototypeAspectInstanceFactory extends BeanFactoryAspectInstanceFactory implements Serializable { 039 040 /** 041 * Create a PrototypeAspectInstanceFactory. AspectJ will be called to 042 * introspect to create AJType metadata using the type returned for the 043 * given bean name from the BeanFactory. 044 * @param beanFactory the BeanFactory to obtain instance(s) from 045 * @param name the name of the bean 046 */ 047 public PrototypeAspectInstanceFactory(BeanFactory beanFactory, String name) { 048 super(beanFactory, name); 049 if (!beanFactory.isPrototype(name)) { 050 throw new IllegalArgumentException( 051 "Cannot use PrototypeAspectInstanceFactory with bean named '" + name + "': not a prototype"); 052 } 053 } 054 055}