There is a main class that contains the configuration of the beans.

package start; @Configuration @EnableAspectJAutoProxy(proxyTargetClass = true) public class Main { public static void main(String[] args) { ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Main.class); Post post = new Post(); post.setFrom("User102"); java.util.Date date = new java.util.Date(); post.setDate(new Date(date.getTime())); post.setName("Named Post"); new Main().shopImpl().addPost(post); } @Bean public SimpleJdbcTemplate template(){ DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("root"); dataSource.setPassword("root"); dataSource.setUrl("jdbc:mysql://localhost:3306/shop?useLegacyDatetimeCode=false&serverTimezone=UTC"); return new SimpleJdbcTemplate(dataSource); } @Bean public shopDAO shopImpl(){ shopDAOimpl s = new shopDAOimpl(); s.setSimpleJdbcTemplate(template()); return s; } @Bean public Logging logging(){ System.out.println("LOGGGER CREATED"); return new Logging(); } } 

Aspect class:

  @Aspect public class Logging { @Pointcut("execution(* *.addPost(..))") public void exec(){} @Before("exec()") public void before(){ System.out.println("GETTING ALL POSTS"); } @After("exec()") public void after(){ System.out.println("AFTER GETTIN ALL POSTS"); } } 

Well, the DAO interface and its implementation:

  public interface shopDAO { void addPost(Post post); Post getPostById(long id); void dropPostById(long id); List<Post> getAllPosts(String id); } 

Question: Why does the aspect absolutely not react to the call to the addPost method?

  • I can assume that DAO creates its own proxies and therefore does not work. But this is an assumption. - Tsyklop

0