Skip to content

Commit

Permalink
add Spring dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
QinJiangbo committed Jan 12, 2017
1 parent 3859f6a commit 30b0cac
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 72 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 0 additions & 72 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions OkAOP.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration>
<fileset id="fileset" name="Spring Application Context" removed="false">
<file>file://$MODULE_DIR$/src/main/resources/spring-aop.xml</file>
</fileset>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Expand All @@ -25,5 +34,6 @@
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.4.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.4.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-test:4.3.4.RELEASE" level="project" />
</component>
</module>
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@
<artifactId>spring-context</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
</dependencies>
</project>
23 changes: 23 additions & 0 deletions src/main/java/com/qinjiangbo/test/BookAspect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.qinjiangbo.test;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
* @date: 12/01/2017 1:40 PM
* @author: [email protected]
*/
@Aspect
@Component
public class BookAspect {

@Before("execution(* com.qinjiangbo.test.*.*(..))")
public void logBefore(JoinPoint joinPoint) {
System.out.println(joinPoint.getSignature().getName()
+ "(" + Arrays.asList(joinPoint.getArgs()) + ")");
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/qinjiangbo/test/BookService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.qinjiangbo.test;

import org.springframework.stereotype.Component;

/**
* @date: 12/01/2017 1:39 PM
* @author: [email protected]
*/
@Component
public class BookService {

public void searchBook(long bookId) {
System.out.println("searching book " + bookId);
}
}
17 changes: 17 additions & 0 deletions src/main/resources/spring-aop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">

<context:annotation-config/>
<context:component-scan base-package="com.qinjiangbo.test"/>

<aop:aspectj-autoproxy proxy-target-class="true"/>
</beans>
23 changes: 23 additions & 0 deletions src/test/java/BookAspectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import com.qinjiangbo.test.BookService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
* @date: 12/01/2017 1:42 PM
* @author: [email protected]
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring-aop.xml"})
public class BookAspectTest {

@Autowired
private BookService bookService;

@Test
public void testSearch() {
bookService.searchBook(17783l);
}
}

0 comments on commit 30b0cac

Please sign in to comment.