{"id":21760,"date":"2014-02-19T16:00:46","date_gmt":"2014-02-19T14:00:46","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=21760"},"modified":"2014-02-19T12:24:37","modified_gmt":"2014-02-19T10:24:37","slug":"applying-aspect-oriented-programming","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html","title":{"rendered":"Applying aspect oriented programming"},"content":{"rendered":"<h2>1.Introduction<\/h2>\n<p>The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns we are referring to generic functionality that is used in several places in our system or application. These concepts are, among others:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<ul>\n<li>Logging<\/li>\n<li>Transaction management<\/li>\n<li>Error handling<\/li>\n<li>Monitoring<\/li>\n<li>Security<\/li>\n<\/ul>\n<p>The way to achieve this separation is by modularizing these concepts. This will allow us to keep our business logic classes clean, containing only the code for which the class was designed. If we don&#8217;t modularize these concerns, it will lead to code tangling (the class contains different concerns) and code scattering (the same concern will be spread across the system).<\/p>\n<p>In this example, we have a Spring MVC application that access the requested data (clients and orders) and shows a page with its information. We can take a look at the different layers:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/02\/aop1.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/02\/aop1-300x213.png\" alt=\"aop1\" width=\"300\" height=\"213\" class=\"aligncenter size-medium wp-image-21874\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/02\/aop1-300x213.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/02\/aop1.png 989w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In the above graphic, we can appreciate that there are functionalities spread across different classes (monitoring is implemented in every service), and some classes contain different concerns (for example, the class ClientController contains logging and exception handling). In order to fix that, we will write aspects to implement our cross-cutting concerns. The goal is to implement the following model:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/02\/aop2.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/02\/aop2-300x101.png\" alt=\"aop2\" width=\"300\" height=\"101\" class=\"aligncenter size-medium wp-image-21875\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/02\/aop2-300x101.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/02\/aop2.png 940w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Each class contains only the business logic related code, while the aspects will be responsible of intercepting the code in order to inject the cross-cutting concerns.<\/p>\n<p>Let&#8217;s see this with an example.<\/p>\n<ul>\n<li>Source code can be found at <a href=\"https:\/\/github.com\/xpadro\/spring-aop\" target=\"_blank\">github<\/a>.<\/li>\n<\/ul>\n<h2>2.Checking controller code<\/h2>\n<p>ClientController:<\/p>\n<pre class=\"brush:java\">@Controller\r\npublic class ClientController {\r\n    @Autowired\r\n    private ClientService clientService;\r\n    private static Logger mainLogger = LoggerFactory.getLogger(\"generic\");\r\n    private static Logger errorLogger = LoggerFactory.getLogger(\"errors\");\r\n\r\n    @RequestMapping(\"\/getClients\")\r\n    public String getClients(Model model, @RequestParam(\"id\") int id) {\r\n        mainLogger.debug(\"Executing getClients request\");\r\n        \r\n        try {\r\n            Client client = clientService.getClient(id);\r\n            model.addAttribute(\"client\", client);\r\n        } catch (DataAccessException e) {\r\n            errorLogger.error(\"error in ClientController\", e);\r\n            NotificationUtils.sendNotification(e);\r\n            return \"errorPage\";\r\n        }\r\n        \r\n        return \"showClient\";\r\n    }\r\n}<\/pre>\n<p>The objective of this controller consists in retrieving a client and returning a view showing its information but, as you can see, this code contains additional logic. In one hand, it handles exceptions that may be thrown by the service and it redirects to an error page. On the other hand, it generates logging information and notification sending in case of error. All this code is generic to all controllers in this application (and probably to other classes).<\/p>\n<p>It&#8217;s true that we could have used the @ControllerAdvice annotation to centralize exception handling, but the target of this post is to see how to accomplish it with Spring AOP.<\/p>\n<p>The same happens with the order controller. I won&#8217;t include it here because I don&#8217;t want to make the post unnecessary long. If you want to check it out, you can get the source code included in the previous link.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>3.Checking services code<\/h2>\n<p>ClientService:<\/p>\n<pre class=\"brush:java\">@Service(\"clientService\")\r\npublic class ClientServiceImpl implements ClientService {\r\n    @Autowired\r\n    private ClientRepository clientRepository;\r\n    private static Logger mainLogger = LoggerFactory.getLogger(\"generic\");\r\n    private static Logger monitorLogger = LoggerFactory.getLogger(\"monitoring\");\r\n    \r\n    @Override\r\n    @Transactional(readOnly = true)\r\n    public Client getClient(int id) {\r\n        mainLogger.debug(\"Accessing client service\");\r\n        long startTime = System.currentTimeMillis();\r\n        Client client = clientRepository.getClient(id);\r\n        long totalTime = System.currentTimeMillis() - startTime;\r\n        monitorLogger.info(\"Invocation time {}ms \", totalTime);\r\n        \r\n        return client;\r\n    }\r\n}<\/pre>\n<p>In addition to the service invocation, it also contains logging generation and monitoring of the execution time in each invocation.<\/p>\n<p>We could also use aspects to modularize transaction management if we needed to use programmatic transaction management, but it&#8217;s not the case in this example.<\/p>\n<h2>4.Data access layer<\/h2>\n<p>ClientRepositoryImpl:<\/p>\n<pre class=\"brush:java\">@Repository\r\npublic class ClientRepositoryImpl implements ClientRepository {\r\n    private JdbcTemplate template;\r\n    private RowMapper&lt;Client&gt; rowMapper = new ClientRowMapper();\r\n    private static final String SEARCH = \"select * from clients where clientId = ?\";\r\n    private static final String COLUMN_ID = \"clientId\";\r\n    private static final String COLUMN_NAME = \"name\";\r\n    \r\n    public ClientRepositoryImpl() {}\r\n    \r\n    public ClientRepositoryImpl(DataSource dataSource) {\r\n        this.template = new JdbcTemplate(dataSource);\r\n    }\r\n    \r\n    public Client getClient(int id) {\r\n        return template.queryForObject(SEARCH, rowMapper, id);\r\n    }\r\n    \r\n    private class ClientRowMapper implements RowMapper&lt;Client&gt; {\r\n        public Client mapRow(ResultSet rs, int i) throws SQLException {\r\n            Client client = new Client();\r\n            client.setClientId(rs.getInt(COLUMN_ID));\r\n            client.setName(rs.getString(COLUMN_NAME));\r\n            \r\n            return client;\r\n        }\r\n    }\r\n}<\/pre>\n<p>This code does not contain any cross-cutting concern but I&#8217;ve included it to show all the sample application layers.<\/p>\n<h2>5.Activating AOP<\/h2>\n<p>To configure AOP, it is necessary to import the following dependencies:<\/p>\n<pre class=\"brush:xml\">&lt;dependency&gt;\r\n    &lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;spring-aop&lt;\/artifactId&gt;\r\n    &lt;version&gt;3.2.1.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n    &lt;groupId&gt;org.aspectj&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;aspectjweaver&lt;\/artifactId&gt;\r\n    &lt;version&gt;1.6.8&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>In the Spring configuration file, we need to add the following tags:<\/p>\n<pre class=\"brush:xml\">&lt;context:component-scan base-package=\"xpadro.spring.mvc.aop\"\/&gt;\r\n&lt;aop:aspectj-autoproxy\/&gt;<\/pre>\n<p>The component-scan tag will search within the base package in order to find our aspects. To use auto scan, you not only need to define the aspect class with @Aspect annotation, but also you will need to include @Component annotation. If you don&#8217;t include @Component you will need to define the aspect in the xml configuration file.<\/p>\n<h2>6.Centralizing error handling<\/h2>\n<p>We&#8217;ll write an aspect with an @Around advice. This advice will intercept every method annotated with @RequestMapping annotation and will be responsible of invoking it, catching exceptions thrown by the service.<\/p>\n<pre class=\"brush:java\">@Component\r\n@Aspect\r\npublic class CentralExceptionHandler {\r\n    private static Logger errorLogger = LoggerFactory.getLogger(\"errors\");\r\n    \r\n    @Around(\"@annotation(org.springframework.web.bind.annotation.RequestMapping) && target(controller)\")\r\n    public String handleException(ProceedingJoinPoint jp, Object controller) throws Throwable {\r\n        String view = null;\r\n        \r\n        try {\r\n            view = (String) jp.proceed();\r\n        } catch (DataAccessException e) {\r\n            errorLogger.error(\"error in {}\", controller.getClass().getSimpleName(), e);\r\n            NotificationUtils.sendNotification(e);\r\n            return \"errorPage\";\r\n        }\r\n        \r\n        return view;\r\n    }\r\n}<\/pre>\n<p>The @Target annotation allows us to reference the intercepted class. Now we have the exception handling handled by the aspect so we can get rid of this logic in our controllers.<\/p>\n<pre class=\"brush:java\">@Controller\r\npublic class ClientController {\r\n    @Autowired\r\n    private ClientService clientService;\r\n    private static Logger mainLogger = LoggerFactory.getLogger(\"generic\");\r\n    \/\/private static Logger errorLogger = LoggerFactory.getLogger(\"errors\");\r\n    \r\n    @RequestMapping(\"\/getClients\")\r\n    public String getClients(Model model, @RequestParam(\"id\") int id) {\r\n        mainLogger.debug(\"Executing getClients request\");\r\n        \r\n        \/\/try {\r\n            Client client = clientService.getClient(id);\r\n            model.addAttribute(\"client\", client);\r\n        \/\/} catch (DataAccessException e) {\r\n            \/\/errorLogger.error(\"error in ClientController\", e);\r\n            \/\/NotificationUtils.sendNotification(e);\r\n            \/\/return \"errorPage\";\r\n        \/\/}\r\n        \r\n        return \"showClient\";\r\n    }\t\r\n}<\/pre>\n<p>Just a note, you could have intercepted exceptions thrown by the controller with the following advice:<\/p>\n<pre class=\"brush:java\">@AfterThrowing(pointcut=\"@annotation(org.springframework.web.bind.annotation.RequestMapping)\", throwing=\"e\")<\/pre>\n<p>But be aware that this advice will not prevent the exception from propagating.<\/p>\n<h2>7.Centralizing logging<\/h2>\n<p>The logging aspect will have two advices, one for controller logging and another one for service logging:<\/p>\n<pre class=\"brush:java\">@Aspect\r\n@Component\r\npublic class CentralLoggingHandler {\r\n    private static Logger mainLogger = LoggerFactory.getLogger(\"generic\");\r\n    \r\n    @Before(\"@annotation(org.springframework.web.bind.annotation.RequestMapping) && @annotation(mapping)\")\r\n    public void logControllerAccess(RequestMapping mapping) {\r\n        mainLogger.debug(\"Executing {} request\", mapping.value()[0]);\r\n    }\r\n    \r\n    @Before(\"execution(* xpadro.spring.mvc.*..*Service+.*(..)) && target(service)\")\r\n    public void logServiceAccess(Object service) {\r\n        mainLogger.debug(\"Accessing {}\", service.getClass().getSimpleName());\r\n    }\r\n}<\/pre>\n<h2>8.Finally, the monitoring concern<\/h2>\n<p>We will write another aspect for monitoring concern. The advice is as follows:<\/p>\n<pre class=\"brush:java\">@Aspect\r\n@Component\r\npublic class CentralMonitoringHandler {\r\n    private static Logger monitorLogger = LoggerFactory.getLogger(\"monitoring\");\r\n    \r\n    @Around(\"execution(* xpadro.spring.mvc.*..*Service+.*(..)) && target(service)\")\r\n    public Object logServiceAccess(ProceedingJoinPoint jp, Object service) throws Throwable {\r\n        long startTime = System.currentTimeMillis();\r\n        Object result = jp.proceed();\r\n        long totalTime = System.currentTimeMillis() - startTime;\r\n        monitorLogger.info(\"{}|Invocation time {}ms \", service.getClass().getSimpleName(), totalTime);\r\n        \r\n        return result;\r\n    }\r\n}<\/pre>\n<h2>9.Checking the final code<\/h2>\n<p>After we have modularized all the cross-cutting concerns, our controllers and services contain only the business logic:<\/p>\n<pre class=\"brush:java\">@Controller\r\npublic class ClientController {\r\n    @Autowired\r\n    private ClientService clientService;\r\n    \r\n    @RequestMapping(\"\/getClients\")\r\n    public String getClients(Model model, @RequestParam(\"id\") int id) {\r\n    \tClient client = clientService.getClient(id);\r\n    \tmodel.addAttribute(\"client\", client);\r\n    \t\r\n    \treturn \"showClient\";\r\n    }\t\r\n}\r\n\r\n\r\n@Service(\"clientService\")\r\npublic class ClientServiceImpl implements ClientService {\r\n    @Autowired\r\n    private ClientRepository clientRepository;\r\n    \r\n    @Override\r\n    @Transactional(readOnly = true)\r\n    public Client getClient(int id) {\r\n        return clientRepository.getClient(id);\r\n    }\r\n}<\/pre>\n<h2>10.Conclusion<\/h2>\n<p>We have seen how to apply aspect oriented programming to keep our code clean and focused to the logic for which it was designed. Before using AOP, just take into account its known limitations.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/xpadro.blogspot.com\/2013\/06\/applying-aspect-oriented-programming.html\">Applying aspect oriented programming<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Xavier Padro at the <a href=\"http:\/\/xpadro.blogspot.com\/\">Xavier Padr\u00f3&#8217;s Blog<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1.Introduction The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns we are referring to generic functionality that is used in several places in our system or application. These concepts are, among others: &nbsp; &nbsp; &nbsp; &nbsp; Logging Transaction management Error handling Monitoring Security The &hellip;<\/p>\n","protected":false},"author":533,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[252,74,30],"class_list":["post-21760","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-aop","tag-aspect-oriented-programming","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Applying aspect oriented programming<\/title>\n<meta name=\"description\" content=\"1.Introduction The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Applying aspect oriented programming\" \/>\n<meta property=\"og:description\" content=\"1.Introduction The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-02-19T14:00:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Xavier Padro\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/xavips\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Xavier Padro\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html\"},\"author\":{\"name\":\"Xavier Padro\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/5443fbc8fb815652f181942d4622090d\"},\"headline\":\"Applying aspect oriented programming\",\"datePublished\":\"2014-02-19T14:00:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html\"},\"wordCount\":770,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"AOP\",\"Aspect Oriented Programming\",\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html\",\"name\":\"Applying aspect oriented programming\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2014-02-19T14:00:46+00:00\",\"description\":\"1.Introduction The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/02\\\/applying-aspect-oriented-programming.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Applying aspect oriented programming\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/5443fbc8fb815652f181942d4622090d\",\"name\":\"Xavier Padro\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bbf0579a188773b88762d54dadc779b2cd17ddb261d809956ed55d8569bd7ca2?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bbf0579a188773b88762d54dadc779b2cd17ddb261d809956ed55d8569bd7ca2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bbf0579a188773b88762d54dadc779b2cd17ddb261d809956ed55d8569bd7ca2?s=96&d=mm&r=g\",\"caption\":\"Xavier Padro\"},\"description\":\"Xavier is a software developer working in a consulting firm based in Barcelona. He is specialized in web application development with experience in both frontend and backend. He is interested in everything related to Java and the Spring framework.\",\"sameAs\":[\"http:\\\/\\\/xpadro.blogspot.gr\\\/\",\"http:\\\/\\\/linkedin.com\\\/pub\\\/xavier-padro-sobrepera\\\/1a\\\/64\\\/3\\\/en\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/xavips\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/xavier-padro\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Applying aspect oriented programming","description":"1.Introduction The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html","og_locale":"en_US","og_type":"article","og_title":"Applying aspect oriented programming","og_description":"1.Introduction The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns","og_url":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-02-19T14:00:46+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Xavier Padro","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/xavips","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Xavier Padro","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html"},"author":{"name":"Xavier Padro","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/5443fbc8fb815652f181942d4622090d"},"headline":"Applying aspect oriented programming","datePublished":"2014-02-19T14:00:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html"},"wordCount":770,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["AOP","Aspect Oriented Programming","Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html","url":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html","name":"Applying aspect oriented programming","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2014-02-19T14:00:46+00:00","description":"1.Introduction The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/02\/applying-aspect-oriented-programming.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Applying aspect oriented programming"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/5443fbc8fb815652f181942d4622090d","name":"Xavier Padro","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/bbf0579a188773b88762d54dadc779b2cd17ddb261d809956ed55d8569bd7ca2?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/bbf0579a188773b88762d54dadc779b2cd17ddb261d809956ed55d8569bd7ca2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bbf0579a188773b88762d54dadc779b2cd17ddb261d809956ed55d8569bd7ca2?s=96&d=mm&r=g","caption":"Xavier Padro"},"description":"Xavier is a software developer working in a consulting firm based in Barcelona. He is specialized in web application development with experience in both frontend and backend. He is interested in everything related to Java and the Spring framework.","sameAs":["http:\/\/xpadro.blogspot.gr\/","http:\/\/linkedin.com\/pub\/xavier-padro-sobrepera\/1a\/64\/3\/en","https:\/\/x.com\/https:\/\/twitter.com\/xavips"],"url":"https:\/\/www.javacodegeeks.com\/author\/xavier-padro"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/21760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/533"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=21760"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/21760\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=21760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=21760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=21760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}