general formatting work
This commit is contained in:
@@ -24,13 +24,16 @@ public class LoggingAspect {
|
||||
};
|
||||
|
||||
@Pointcut("@target(org.springframework.stereotype.Repository)")
|
||||
public void repositoryMethods() {}
|
||||
public void repositoryMethods() {
|
||||
}
|
||||
|
||||
@Pointcut("@annotation(org.baeldung.aop.annotations.Loggable)")
|
||||
public void loggableMethods() {}
|
||||
public void loggableMethods() {
|
||||
}
|
||||
|
||||
@Pointcut("@args(org.baeldung.aop.annotations.Entity)")
|
||||
public void methodsAcceptingEntities() {}
|
||||
public void methodsAcceptingEntities() {
|
||||
}
|
||||
|
||||
@Before("repositoryMethods()")
|
||||
public void logMethodCall(JoinPoint jp) {
|
||||
|
||||
@@ -16,7 +16,8 @@ public class PerformanceAspect {
|
||||
private static Logger logger = Logger.getLogger(PerformanceAspect.class.getName());
|
||||
|
||||
@Pointcut("within(@org.springframework.stereotype.Repository *)")
|
||||
public void repositoryClassMethods() {}
|
||||
public void repositoryClassMethods() {
|
||||
}
|
||||
|
||||
@Around("repositoryClassMethods()")
|
||||
public Object measureMethodExecutionTime(ProceedingJoinPoint pjp) throws Throwable {
|
||||
|
||||
@@ -21,13 +21,16 @@ public class PublishingAspect {
|
||||
}
|
||||
|
||||
@Pointcut("@target(org.springframework.stereotype.Repository)")
|
||||
public void repositoryMethods() {}
|
||||
public void repositoryMethods() {
|
||||
}
|
||||
|
||||
@Pointcut("execution(* *..create*(Long,..))")
|
||||
public void firstLongParamMethods() {}
|
||||
public void firstLongParamMethods() {
|
||||
}
|
||||
|
||||
@Pointcut("repositoryMethods() && firstLongParamMethods()")
|
||||
public void entityCreationMethods() {}
|
||||
public void entityCreationMethods() {
|
||||
}
|
||||
|
||||
@AfterReturning(value = "entityCreationMethods()", returning = "entity")
|
||||
public void logMethodCall(JoinPoint jp, Object entity) throws Throwable {
|
||||
|
||||
@@ -14,9 +14,6 @@ public class Foo {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Foo{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
return "Foo{" + "id=" + id + ", name='" + name + '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,19 @@ public class UserController {
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public String showForm(final Model model) {
|
||||
final User user = new User();
|
||||
user.setFirstname("John");
|
||||
user.setLastname("Roy");
|
||||
user.setEmailId("John.Roy@gmail.com");
|
||||
model.addAttribute("user", user);
|
||||
return "index";
|
||||
final User user = new User();
|
||||
user.setFirstname("John");
|
||||
user.setLastname("Roy");
|
||||
user.setEmailId("John.Roy@gmail.com");
|
||||
model.addAttribute("user", user);
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/processForm", method = RequestMethod.POST)
|
||||
public String processForm(@ModelAttribute(value = "user") final User user,
|
||||
final Model model) {
|
||||
// Insert User into DB
|
||||
model.addAttribute("name", user.getFirstname() + " " + user.getLastname());
|
||||
return "hello";
|
||||
public String processForm(@ModelAttribute(value = "user") final User user, final Model model) {
|
||||
// Insert User into DB
|
||||
model.addAttribute("name", user.getFirstname() + " " + user.getLastname());
|
||||
return "hello";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { TestConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class AopLoggingTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
messages = new ArrayList<>();
|
||||
messages = new ArrayList<>();
|
||||
|
||||
logEventHandler = new Handler() {
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { TestConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class AopPerformanceTest {
|
||||
|
||||
@Before
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.regex.Pattern;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { TestConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class AopPublishingTest {
|
||||
|
||||
@Before
|
||||
@@ -60,8 +60,7 @@ public class AopPublishingTest {
|
||||
dao.create(1L, "Bar");
|
||||
|
||||
String logMessage = messages.get(0);
|
||||
Pattern pattern = Pattern.compile("Created foo instance: " +
|
||||
Pattern.quote(new Foo(1L, "Bar").toString()));
|
||||
Pattern pattern = Pattern.compile("Created foo instance: " + Pattern.quote(new Foo(1L, "Bar").toString()));
|
||||
assertTrue(pattern.matcher(logMessage).matches());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"org.baeldung.dao", "org.baeldung.aop", "org.baeldung.events"})
|
||||
@ComponentScan(basePackages = { "org.baeldung.dao", "org.baeldung.aop", "org.baeldung.events" })
|
||||
@EnableAspectJAutoProxy
|
||||
public class TestConfig {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user