2016-04-02 10 views
1

注釈:パス結果

@Target(ElementType.METHOD) 
@Retention(RetentionPolicy.RUNTIME) 
public @interface Multipart { 

    Class acceptClass(); 

} 

注釈方法:

@Multipart (acceptClass = SomeClass.class) 
public void someMethod(SomeClass a){ 
    //do stuff.. 
} 

MultipartAspect:

@Aspect 
public class MultipartAspect { 

    @Autowired(required=true) 
    private HttpServletRequest request; 

    @Pointcut(value = "@annotation(Multipart)", argNames = "multipart") 
    public void before(JoinPoint jp, Multipart multipart) {} 

    @Before("before()") 
    public SomeClass doStuffBeforeThing() { 
     SomeClass sc = new SomeClass(); //object of passed class 
     //do something.. 
     return sc;      //return this to annotated method(somemethod) 
    } 

} 

は、私は方法の作品は、アノテーションを実行する前に、のオブジェクトを作成したいですクラス(SomeClass)とこのクラスのpassオブジェクトを注釈付きメソッドに渡します。私はこれを行うことができますか?

答えて

0

@Beforeの代わりに@Aroundアドバイスを使用する必要があります。