0

I'm want to use Aspectj in project. I created helloworld basic servlet project. When I deploy my project on Wildfly 14, I don't see any logs on Wilfly 14.0 console from MyAspect class. I am not sure about to add anything my code or Wildfly 14.0. Here my classes,

MyAspect

@Aspect
public class MyAspect {

    static Logger logger = Logger.getLogger("MyAspect");

    @Before("execution(* org.jboss.as.quickstarts.helloworld.HelloService.*(..))")
    public void testModeOnlyMethods() {
        logger.info("AspectLog");
    }
} 

HelloWorldServlet

public class HelloWorldServlet extends HttpServlet {

    static String PAGE_HEADER = "<html><head><title>helloworld</title></head><body>";

    static String PAGE_FOOTER = "</body></html>";

    @Inject
    HelloService helloService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        PrintWriter writer = resp.getWriter();
        writer.println(PAGE_HEADER);
        writer.println("<h1>" + helloService.createHelloMessage("World") + "</h1>");
        writer.println(PAGE_FOOTER);
        writer.close();
    }

}

HelloService

public class HelloService {

    static Logger logger = Logger.getLogger("HelloService");

    String createHelloMessage(String name) {
        logger.info("Aspect");
        return "Hello " + name + "!";
    }
}

Project Structure

enter image description here

Gastón Schabas
  • 2,153
  • 1
  • 10
  • 17
26Boyka
  • 21
  • 1
  • 4
  • How are you building and how are you configuring your app? I don't think JEE will run AspectJ out of the box (unless something changed the last years, I haven't used it for some time). Also, since you are using CDI, you could take a look at standard JEE interceptors; less powerful than AspectJ, but will do for most of the use cases. – Nikos Paraskevopoulos Jun 16 '23 at 08:34
  • 1
    Are you trying to use load-time weaving (LTW) or compile-time weaving (CTW)? In case of LTW, where is your _aop.xml_? In case of CTW, where is your build configuration for the AspectJ compiler? – kriegaex Jun 16 '23 at 08:36
  • @kriegaex thanks for your comment. I did read all about aspectj page on Internet but I have never come across such a concept that you wrote about CTW and LTW. I compiled with plugin with "aspectj-maven-plugin" for CTW and it worked. Problem solved. Thanks a lot again. – 26Boyka Jun 16 '23 at 16:49

0 Answers0