Есть странная проблема с аннотацией springboot. Я создал 3 файла следующим образом.
1.@Interface file1
package com.UserOp.Controller.annotation;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Documented
@Retention(RUNTIME)
@Target(METHOD)
public @interface helloX {
String value() default "Hello Aop.";
}
2.@Aspect file2
package com.UserOp.Controller.annotation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class helloXAspect {
@Pointcut("@annotation(com.UserOp.Controller.annotation.helloX)")
private void cut() { }
@Around("cut()")
public void advice(ProceedingJoinPoint joinPoint){
System.out.println("Around begin.");
try {
joinPoint.proceed();
} catch (Throwable e) {
e.printStackTrace();
}
System.out.println("Around end.");
}
}
3.test class file3
package com.UserOp.Controller.annotation;
import org.springframework.stereotype.Service;
@Service
public class ABC {
@helloX
public void test()
{
System.out.println("int hellox test.");
}
}
4.//spring boot run file4,
package com.UserOp.Controller.useropControllers;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;
import com.UserOp.Controller.annotation.ABC;
import com.UserOp.Controller.annotation.helloX;
import com.UserOp.DbModel.Users.Cloud_UsersRepository;
import MyJ_CommonLib.MyJ_ReqResult;
import annotation.MyResponseBody;
@Component
public class userController {
@Autowired
ABC abc;
public String UserOp(HttpSession session, HttpServletRequest request, Object object) {
test();
return "";
}
//@helloX
void test()
{
System.out.println("prepar test!");
abc.test();
return;
}
}
//The above file is invoked as follows
package com.UserOp.Controller;
....
@RestController
public class DoController {
@Autowired
userController a_userController;
...
@RequestMapping(value="/Do",method=RequestMethod.GET)
public String doRoute(@RequestParam String mode,@RequestParam String action
,@RequestParam(required=false) String process,HttpSession session,HttpServletRequest request) throws Exception
{
a_userController.UserOp(session,request,null);
return "";
}
...
Please see the file4,There are two things going on here.
//first,all be right.annotation '@helloX' excute on abc.test();
void test()
{
System.out.println("prepar test!");
abc.test();
return;
}
//but this is error.
@helloX //look there,add this notation than nothing happened.
void test()
{
System.out.println("prepar test!");
//abc.test();
return;
}
Я не знаю, почему добавление @helloX в file3 работает нормально (abc.test (), нодобавление @helloX в file4 не работает и сообщает об ошибке в режиме отладки:
Unable to install breakpoint in com.UserOp.Controller.useropControllers
.userController$$FastClassBySpringCGLIB$$3389c207
due to missing line number attributes.
Modify compiler options to generate line number attributes.
Reason:
Absent Line Number Information