[{"data":1,"prerenderedAt":331},["ShallowReactive",2],{"Categories":3,"NavIndexCategoriesCountFooter":203,"content-\u002F2008\u002F05\u002F22\u002Fspring-aspects-configurable-and-compile-time-weaving-using-maven\u002F":204},[4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,68,70,71,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202],{"category":5},"System Administration",{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},"Software Development",{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":27},{"category":27},{"category":67},"Drones & RC",{"category":69},"DIY Projects",{"category":67},{"category":72},"Photography",{"category":69},{"category":69},{"category":69},{"category":67},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":67},{"category":69},{"category":69},{"category":67},{"category":67},{"category":72},{"category":72},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":5},{"category":5},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":5},{"category":67},{"category":67},{"category":72},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":72},{"category":67},{"category":138},"3D Printing - Laser Cutting - CNC",{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":5},{"category":138},{"category":27},{"category":27},{"category":138},{"category":138},{"category":72},{"category":158},"Photography,3D Printing - Laser Cutting - CNC",{"category":27},{"category":27},{"category":69},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":67},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":27},{"category":69},{"category":27},{"category":27},{"category":27},{"category":27},{"category":181},"Home Assistant",{"category":181},{"category":72},{"category":27},{"category":27},{"category":72},{"category":138},{"category":5},{"category":72},{"category":72},{"category":138},{"category":27},{"category":181},{"category":181},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},191,{"id":205,"title":206,"body":207,"category":27,"date":314,"description":213,"embedImage":315,"extension":316,"image":315,"intro":315,"meta":317,"navigation":318,"path":319,"seo":320,"series":315,"sitemap":321,"stem":322,"tags":323,"__hash__":330},"content\u002F2008\u002F05\u002F22\u002Fspring-aspects-configurable-and-compile-time-weaving-using-maven.md","Spring, Aspects, @Configurable and Compile Time Weaving using maven",{"type":208,"value":209,"toc":311},"minimark",[210,214,217,220,223,226,240,243,246,249,260,266,269,272,278,281,284,290,293,296,302],[211,212,213],"p",{},"Why do most people use Load Time Weaving (LTW)? It requires replacing the javaagent\u002Fclassloader of your JVM which can lead to all sorts of issues.",[211,215,216],{},"Let's take a look at getting Compile Time Weaving (CTW) instead.",[211,218,219],{},"This post is using spring 2.5.2, aspectj 1.5.4, java 1.5. (Spring 2.5.4 uses a later version of weaver (3.0 vs. 5.0) - I assume AspectJ 1.6.0 but the aspectj-maven-plugin is also based around 1.5.4 - so for now we'll stick with this combination.)",[211,221,222],{},"In spring, we can simply inject resources to normal spring beans, either via the spring context configuration, or by using the support for annotation based injection (@Resource, @Autowired together with @Repository, @Service etc).",[211,224,225],{},"However - beans that are of scope=\"prototype\" are harder to handle. They are often new'ed (Bean foo = new FooBean();) either by the developer or by external frameworks (Hibernate for model beans, servlet containers for servlets etc etc).",[211,227,228,229,239],{},"The ",[230,231,238],"a",{"href":232,"rel":233,"target":237},"http:\u002F\u002Fwww.springsource.org\u002F",[234,235,236],"nofollow","noopener","noreferer","_blank","spring framework"," provides the @Configurable annotation for this.",[211,241,242],{},"Any bean that is annotated @Configurable will - by utilising aspects be injected with its properties. So - we need to get things prepared so that this aspect weaving can happen.",[211,244,245],{},"Firstly - the spring context.",[211,247,248],{},"You will need the following in your application context:",[250,251,256],"pre",{"className":252,"code":254,"language":255},[253],"language-text","\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\u003Cbeans xmlns=\"http:\u002F\u002Fwww.springframework.org\u002Fschema\u002Fbeans\"\n   xmlns:xsi=\"http:\u002F\u002Fwww.w3.org\u002F2001\u002FXMLSchema-instance\"\n   \u003Cb>xmlns:context=\"http:\u002F\u002Fwww.springframework.org\u002Fschema\u002Fcontext\"\u003C\u002Fb>\n   xsi:schemaLocation=\"http:\u002F\u002Fwww.springframework.org\u002Fschema\u002Fbeans&nbsp;http:\u002F\u002Fwww.springframework.org\u002Fschema\u002Fbeans\u002Fspring-beans-2.5.xsd\n       \u003Cb>http:\u002F\u002Fwww.springframework.org\u002Fschema\u002Fcontext&nbsp;http:\u002F\u002Fwww.springframework.org\u002Fschema\u002Fcontext\u002Fspring-context-2.5.xsd\u003C\u002Fb>\">\n\n    \u003Cb>\u003Ccontext:component-scan base-package=\"your.package.root\"\u002F>\n    \u003Ccontext:spring-configured\u002F>\u003C\u002Fb>\n\n    .....\n\n\u003C\u002Fbeans>\n","text",[257,258,254],"code",{"__ignoreMap":259},"",[211,261,262],{},[263,264,265],"em",{},"Remember to add the context namespace to the schema declaration in your context file.",[211,267,268],{},"Now the maven config:",[211,270,271],{},"You'll need to use the aspectj-maven-plugin from the codehaus MOJO project.",[250,273,276],{"className":274,"code":275,"language":255},[253],"        \u003Cplugin>\n            \u003CgroupId>org.codehaus.mojo\u003C\u002FgroupId>\n            \u003CartifactId>aspectj-maven-plugin\u003C\u002FartifactId>\n            \u003Cconfiguration>\n                \u003CcomplianceLevel>1.5\u003C\u002FcomplianceLevel>\n                \u003CaspectLibraries>\n                    \u003CaspectLibrary>\n                        \u003CgroupId>org.springframework\u003C\u002FgroupId>\n                        \u003CartifactId>spring-aspects\u003C\u002FartifactId>\n                    \u003C\u002FaspectLibrary>\n                \u003C\u002FaspectLibraries>\n            \u003C\u002Fconfiguration>\n            \u003Cexecutions>\n                \u003Cexecution>\n                    \u003Cgoals>\n                        \u003Cgoal>compile\u003C\u002Fgoal>\n                    \u003C\u002Fgoals>\n                \u003C\u002Fexecution>\n            \u003C\u002Fexecutions>\n        \u003C\u002Fplugin>\n",[257,277,275],{"__ignoreMap":259},[211,279,280],{},"The jars from the aspectLibraries list should contain pre-compiled aspects (in this case spring's) and these aspects will be compile time woven against your code at compile time.",[211,282,283],{},"There is an example available via mercurial",[250,285,288],{"className":286,"code":287,"language":255},[253],"hg clone https:\u002F\u002Fsvn.chrissearle.net\u002Fmercurial\u002Fexamples\n",[257,289,287],{"__ignoreMap":259},[211,291,292],{},"Then look in the aspectj\u002Fctw directory.",[211,294,295],{},"If you don't have mercurial then you can try browsing to",[250,297,300],{"className":298,"code":299,"language":255},[253],"https:\u002F\u002Fsvn.chrissearle.net\u002Fmercurial\u002Fexamples\u002Ffile\u002Ftip\u002Faspectj\u002Fctw\u002F\n",[257,301,299],{"__ignoreMap":259},[211,303,304,305,310],{},"Many thanks to ",[230,306,309],{"href":307,"rel":308,"target":237},"http:\u002F\u002Fkaare-nilsen.com\u002F",[234,235,236],"Kaare Nilsen"," too - one for the maven plugin we need to use and two for patiently answering daft questions.",{"title":259,"searchDepth":312,"depth":312,"links":313},2,[],"2008-05-22 10:09:16 +0200",null,"md",{},true,"\u002F2008\u002F05\u002F22\u002Fspring-aspects-configurable-and-compile-time-weaving-using-maven",{"title":206,"description":213},{"loc":319},"2008\u002F05\u002F22\u002Fspring-aspects-configurable-and-compile-time-weaving-using-maven",[324,325,326,327,328,329],"java","spring","maven","@configurable","aspectj","compile time weaving","I5jcNdgG5E26qDMc5cck0j_8_oyE-uKZDG9YFME9Wao",1775293014806]