Я узнаю, как использовать выражения AspectJ, используя книгу «Spring Begin здесь», и после запуска той же программы 5 раз (это было в порядке) изменение в выражении AspectJ сделало исключение, которое сказано
Exception in thread "main"
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type
'julian.gonzalezlopez.aop.Comment.CommentRepository'
available
Эта ошибка случайна только в том случае, если выражение аспекта соответствует критерию
< /p>
aaspecto.java
import java.util.logging.Logger;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@Aspect
@Component
public class Aspecto {
private static final Logger logger = Logger.getLogger(Aspect.class.getName());
@Around("execution (* julian.*.*.Comment.*.*(..))")
public void log(ProceedingJoinPoint joinPoint) {
logger.info("Comenzó un metodo atrapado por el aspecto");
try {
joinPoint.proceed();
}
catch (Throwable e) {
System.err.println(e);
}
logger.info("Terminó");
}
}
< /code>
commentrepository.java
import julian.gonzalezlopez.aop.POJO.Comment;
import org.springframework.stereotype.Service;
@Service
public class CommentRepository implements CommentRepositoryInterface {
public void pie(Comment comment){
System.out.println(comment.getText());
System.out.println("Escrito por: " + comment.getOwner());
}
}
< /code>
main.java
import julian.gonzalezlopez.aop.Comment.CommentRepository;
import julian.gonzalezlopez.aop.Comment.CommentRepositoryInterface;
import julian.gonzalezlopez.aop.POJO.Comment;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
AnnotationConfigApplicationContext c = new AnnotationConfigApplicationContext(ProjectConfig.class);
System.out.println(c);
CommentRepositoryInterface commentRepository = c.getBean(CommentRepository.class);
Comment comment = new Comment("hola","julian");
commentRepository.pie(comment);
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... ed-to-work