{"id":2833,"date":"2018-05-13T21:08:34","date_gmt":"2018-05-13T12:08:34","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=2833"},"modified":"2023-05-27T23:10:42","modified_gmt":"2023-05-27T14:10:42","slug":"%e3%80%90spring-framework%e3%80%91aop%e3%82%a2%e3%82%b9%e3%83%9a%e3%82%af%e3%83%88%e6%8c%87%e5%90%91%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e3%82%92%e3%80%8caspectj%e3%80%8d","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=2833","title":{"rendered":"\u3010Spring Framework\u3011AOP(\u30a2\u30b9\u30da\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0)\u3092\u300cAspectJ\u300d\u3067\u5b9f\u88c5\u3057\u3066\u307f\u308b\u3002"},"content":{"rendered":"<p>Spring\u3067\u3001\u30a2\u30b9\u30da\u30af\u30c8\u6307\u5411\u306b\u3064\u3044\u3066\u89e3\u8aac\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u304c\u3001<span style=\"color: #ff0000;\"><strong>\u300cAspectJ\u300d<\/strong><\/span>\u3068\u3044\u3046\u5916\u90e8\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u3092\u4f7f\u3063\u3066\u3082\u3063\u3068\u697d\u306b\u3001\u30a2\u30b9\u30da\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h2>AspectJ\u3092\u5165\u624b\u3059\u308b\u3002<\/h2>\n<p>\u307e\u305a\u306f\u3001AspectJ\u3092\u5165\u624b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>pom.xml\u306eMaven\u306e\u4f9d\u5b58\u95a2\u4fc2\u306b\u4e0b\u8a18\u306e\u8a18\u8ff0\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&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.9.1&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;aspectjrt&lt;\/artifactId&gt;\r\n    &lt;version&gt;1.9.1&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;aspectjtools&lt;\/artifactId&gt;\r\n    &lt;version&gt;1.9.1&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>\u203b2018\/5\/13\u65e5\u73fe\u5728\u3067\u306f\u3001Maven\u306e\u30bb\u30f3\u30c8\u30e9\u30eb\u30ec\u30dd\u30b8\u30c8\u30ea\u306b\u4e0a\u304c\u3063\u3066\u3044\u308bAspectJ\u306e\u6700\u65b0\u7248\u304c\u300c1.9.1\u300d\u306b\u306a\u3063\u3066\u3044\u305f\u306e\u3067\u4e0a\u8a18\u306e\u8a18\u8ff0\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\u306a\u304a\u3001Maven\u306e\u30bb\u30f3\u30c8\u30e9\u30eb\u30ec\u30dd\u30b8\u30c8\u30ea\u3067\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u78ba\u8a8d\u65b9\u6cd5\u306b\u3064\u3044\u3066\u306f\u3001\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"VQvxZb5pUP\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=2444\">\u3010Maven\u3011\u30bb\u30f3\u30c8\u30e9\u30eb\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u3064\u3044\u3066<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=2444&#038;embed=true#?secret=VQvxZb5pUP\" data-secret=\"VQvxZb5pUP\" width=\"500\" height=\"282\" title=\"&#8220;\u3010Maven\u3011\u30bb\u30f3\u30c8\u30e9\u30eb\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u3064\u3044\u3066&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h3>\u4f9d\u5b58\u95a2\u4fc2\u3067\u3001\u8ffd\u52a0\u3057\u305fAspectJ\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u306b\u3064\u3044\u3066<\/h3>\n<table>\n<tbody>\n<tr>\n<th>\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>aspectjrt<\/td>\n<td>\u300c\u30a2\u30b9\u30da\u30af\u30c8J\u300d\u306e\u30e9\u30f3\u30bf\u30a4\u30e0\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002AspectJ\u306e\u30b3\u30a2\u6a5f\u80fd\u3067\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>aspectjweaver<\/td>\n<td>\u30a2\u30b9\u30da\u30af\u30c8\u60c5\u5831\u3092\u5143\u306b\u3001\u7d44\u307f\u8fbc\u3093\u3060\u30b3\u30fc\u30c9\u3092\u751f\u6210\u3059\u308b\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u3067\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>aspectjtools<\/td>\n<td>\u30a2\u30b9\u30da\u30af\u30c8\u60c5\u5831\u3092\u5143\u306b\u3001\u7d44\u307f\u8fbc\u3093\u3060\u30b3\u30fc\u30c9\u3092\u751f\u6210\u3059\u308b\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u3067\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5b9f\u88c5\u3057\u3066\u307f\u308b\u3002<\/h2>\n<p>\u5b9f\u88c5\u30a4\u30e1\u30fc\u30b8\u306f\u3001\u30af\u30e9\u30b9\u56f3\u306b\u3059\u308b\u3068\u4e0b\u8a18\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2843\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/aspectj_\u30af\u30e9\u30b9\u56f3.png\" alt=\"\" width=\"601\" height=\"336\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/aspectj_\u30af\u30e9\u30b9\u56f3.png 601w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/aspectj_\u30af\u30e9\u30b9\u56f3-300x168.png 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/p>\n<h3>Main.java(\u30e1\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0\uff09<\/h3>\n<pre class=\"lang:default decode:true\">package com.springapp;\r\n\r\nimport org.springframework.context.ApplicationContext;\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\n\r\npublic class Main {\r\n\r\n    public static void main(String[] args) {\r\n        ApplicationContext app = new ClassPathXmlApplicationContext(\"aopbean.xml\");\r\n\r\n        TestBean bean = (TestBean) app.getBean(\"testBean\");\r\n        bean.HelloWorld();\r\n    }\r\n\r\n}\r\n<\/pre>\n<h3>AspectTest.java(AspectJ\u306b\u3088\u308b\u4e8b\u524d\u4e8b\u5f8c\u306b\u6ce8\u5165\u3059\u308b\u51e6\u7406\uff09<\/h3>\n<pre class=\"lang:default decode:true\">package com.springapp;\r\nimport org.aspectj.lang.annotation.After;\r\nimport org.aspectj.lang.annotation.Aspect;\r\nimport org.aspectj.lang.annotation.Before;\r\n\r\n@Aspect\r\npublic class AspectTest {\r\n\r\n    @Before(\"execution(* com.springapp.TestBean.*(..))\")\r\n    public void before() {\r\n        System.out.println(\"\u4e8b\u524d\u51e6\u7406\");\r\n    }\r\n\r\n    @After(\"execution(* com.springapp.TestBean.*(..))\")\r\n    public void after() {\r\n        System.out.println(\"\u4e8b\u5f8c\u51e6\u7406\");\r\n    }\r\n}<\/pre>\n<p>AspectJ\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u306b\u6bd4\u3079\u308b\u3068\u3001<span style=\"color: #ff0000;\"><strong>\u30bd\u30fc\u30b9\u306f\u5c11\u3057\u3059\u3063\u304d\u308a\u3057\u3066\u3044\u308b<\/strong><\/span>\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u300cexecution\u300d\u306b\u3088\u3063\u3066\u3001\u3069\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u51e6\u7406\u3092\u633f\u5165\u3059\u308b\u304b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002AspectJ\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u306f\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u8ff0\u3057\u3066\u3044\u305f\u306e\u3067\u3088\u308a\u76f4\u611f\u7684\u306b\u306a\u308a\u307e\u3057\u305f\u306d\u3002<\/strong><\/span><\/p>\n<h3>\u4f7f\u3063\u3066\u3044\u308b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3<\/h3>\n<table>\n<tbody>\n<tr>\n<th>\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>@Aspect<\/td>\n<td>AspectJ\u3067\u633f\u5165\u3059\u308b\u30af\u30e9\u30b9\u306e\u982d\u306b\u306f\u3053\u308c\u3092\u3064\u3051\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>@Before<\/td>\n<td>\u5b9f\u884c\u524d\u306b\u51e6\u7406\u3055\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3042\u308b\u3053\u3068\u3092\u793a\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>@After<\/td>\n<td>\u5b9f\u884c\u5f8c\u306b\u51e6\u7406\u3055\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3042\u308b\u3053\u3068\u3092\u793a\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>TestBean.java(AspectJ\u306b\u3088\u308a\u6ce8\u5165\u3055\u308c\u308b\u51e6\u7406\uff09<\/h3>\n<pre class=\"lang:default decode:true\">package com.springapp;\r\n\r\npublic class TestBean {\r\n    private String helloWorld;\r\n\r\n    public TestBean() {\r\n        super();\r\n        this.helloWorld = \"Hello World!\";\r\n    }\r\n\r\n    public void setHelloWorld(String helloWorld) {\r\n\t\tthis.helloWorld = helloWorld;\r\n\t}\r\n\r\n\tpublic TestBean(String helloWorld) {\r\n        this.helloWorld = helloWorld;\r\n    }\r\n\r\n    public void HelloWorld() {\r\n        System.out.println(this.helloWorld);\r\n    }\r\n}\r\n<\/pre>\n<h3>aopbean.xml(\u30a2\u30b9\u30da\u30af\u30c8J\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\uff09<\/h3>\n<pre class=\"lang:default decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n    xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n    xmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\"\r\n    xsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans\r\n    http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n    http:\/\/www.springframework.org\/schema\/aop\r\n    http:\/\/www.springframework.org\/schema\/aop\/spring-aop.xsd\"&gt;\r\n\r\n    &lt;bean id=\"sampleAspect\" class=\"com.springapp.AspectTest\" \/&gt;\r\n    &lt;bean id=\"testBean\" class=\"com.springapp.TestBean\" \/&gt;\r\n\t&lt;aop:aspectj-autoproxy \/&gt;\r\n\r\n&lt;\/beans&gt;\r\n<\/pre>\n<p>AspectJ\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u306b\u6bd4\u3079\u308b\u3068\u3001<span style=\"color: #ff0000;\"><strong>\u8a2d\u5b9a\u5185\u5bb9<\/strong><strong>\u306f\u5c11\u3057\u3059\u3063\u304d\u308a\u3057\u3066\u3044\u308b<\/strong><\/span>\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30dd\u30a4\u30f3\u30c8\u306f\u3001\u4e0b\u8a18\u306e\u8a18\u8ff0\u3067\u3001<span style=\"color: #ff0000;\"><strong>\u51e6\u7406\u306e\u633f\u5165\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b\u305f\u3081\u306e\u8a2d\u5b9a\u5185\u5bb9<\/strong><\/span>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;aop:aspectj-autoproxy \/&gt;<\/pre>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2844\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/aspectj_\u5b9f\u884c\u7d50\u679c.png\" alt=\"\" width=\"199\" height=\"156\" \/><\/p>\n<h2>\u6700\u5f8c\u306b<\/h2>\n<p>\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u4e0b\u8a18\u306e\u8a18\u4e8b\u306e\u5185\u5bb9\u3068\u540c\u3058\u3067\u3059\u304c\u3001\u300cAspectJ\u300d\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3088\u308a\u76f4\u611f\u7684\u306b\u3001\u7c21\u5358\u306b\u8a18\u8ff0\u3067\u304d\u305f\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"YiXuouHMVm\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=2788\">\u3010Spring Framework\u3011AOP(\u30a2\u30b9\u30da\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0)\u3092\u5b9f\u88c5\u3057\u3066\u307f\u308b\u3002\uff08\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u5b9f\u88c5\uff09<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=2788&#038;embed=true#?secret=YiXuouHMVm\" data-secret=\"YiXuouHMVm\" width=\"500\" height=\"282\" title=\"&#8220;\u3010Spring Framework\u3011AOP(\u30a2\u30b9\u30da\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0)\u3092\u5b9f\u88c5\u3057\u3066\u307f\u308b\u3002\uff08\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u5b9f\u88c5\uff09&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>Spring\u306b\u3001Aspect\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u5c0e\u5165\u3059\u308b\u306e\u3067\u3042\u308c\u3070\u3001\u305c\u3072\u300cAspectJ\u300d\u306e\u5c0e\u5165\u3092\u691c\u8a0e\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Spring\u3067\u3001\u30a2\u30b9\u30da\u30af\u30c8\u6307\u5411\u306b\u3064\u3044\u3066\u89e3\u8aac\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u304c\u3001\u300cAspectJ\u300d\u3068\u3044\u3046\u5916\u90e8\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u3092\u4f7f\u3063\u3066\u3082\u3063\u3068\u697d\u306b\u3001\u30a2\u30b9\u30da\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002 AspectJ\u3092\u5165\u624b\u3059\u308b\u3002 \u307e [&hellip;]","protected":false},"author":1,"featured_media":2841,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2833"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2833"}],"version-history":[{"count":13,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2833\/revisions"}],"predecessor-version":[{"id":20571,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2833\/revisions\/20571"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/2841"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2833"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}