Skip to content

Commit

Permalink
Working Load-Time Weaving (LTW)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Elsmore-Paddock committed Mar 27, 2017
1 parent 4c5887b commit b204825
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
24 changes: 22 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
configurations {
runtimeAgent
}

buildscript {
ext {
springBootVersion = '1.4.4.RELEASE'
springBootVersion = '1.5.2.RELEASE'
}
repositories {
mavenCentral()
Expand All @@ -25,10 +29,26 @@ repositories {
mavenCentral()
}


dependencies {
compile('org.springframework.boot:spring-boot-starter-aop')
compile("org.springframework.boot:spring-boot-starter-web")

testCompile('org.springframework.boot:spring-boot-starter-test')

runtimeAgent("org.springframework:spring-instrument")
runtimeAgent("org.aspectj:aspectjweaver")
}

test.doFirst {
configurations.runtimeAgent.each {
File jarFile ->
jvmArgs("-javaagent:${jarFile.absolutePath}")
}
}

bootRun.doFirst {
configurations.runtimeAgent.each {
File jarFile ->
jvmArgs("-javaagent:${jarFile.absolutePath}")
}
}
1 change: 0 additions & 1 deletion src/main/java/com/rosieapp/aop/aspect/ProfilingAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.util.StopWatch;

@Aspect
@Component
public class ProfilingAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(ProfilingAspect.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/**
* Created by gkatzioura on 5/28/16.
*/

@Aspect
@Component
public class SampleServiceAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(SampleServiceAspect.class);

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/rosieapp/aop/config/AspectJConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.rosieapp.aop.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableLoadTimeWeaving;
import org.springframework.context.annotation.EnableLoadTimeWeaving.AspectJWeaving;

/**
* @author Guy Paddock (guy@redbottledesign.com)
*/
@Configuration
@EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED)
public class AspectJConfig {
}
12 changes: 12 additions & 0 deletions src/main/resources/META-INF/aop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver options="-verbose -showWeaveInfo">
<!-- only weave classes in our application-specific packages -->
<include within="com.rosieapp.aop..*" />
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.rosieapp.aop.aspect.ProfilingAspect"/>
<aspect name="com.rosieapp.aop.aspect.SampleServiceAspect"/>
</aspects>
</aspectj>

0 comments on commit b204825

Please sign in to comment.