*/
private SpringContextLocator() {
String[] factoryFiles = null;
- System.out.println("Loading files context " +
+ System.out.println("Loading context filex " +
SpringContextLocator.SPRING_CONFIG_CONTEXT);
factoryFiles = new String[] { SPRING_CONFIG_CONTEXT };
* Singleton pattern not thread safety. To use SingletoHolder pattern as the best approximation
* otherwise to use an Enum class (see Effective Java Second Edition and ) if we need serialization.
*/
- public synchronized static SpringContextLocator getInstance() {
+ public static SpringContextLocator getInstance() {
if (SpringContextLocator.instance == null) {
SpringContextLocator.instance = new SpringContextLocator();
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>de.spring.example</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <name>spring-aop</name>
+ <url>http://www.myorganization.de</url>
+ <description>Spring AspectJ with Spring Libraries</description>
+ <organization>
+ <name>MyOrganization</name>
+ <url>http://www.myorganization.de</url>
+ </organization>
+ <packaging>pom</packaging>
+ <issueManagement>
+ <system>trac</system>
+ <url>http://noserver/</url>
+ </issueManagement>
+ <ciManagement>
+ <system>jenkins</system>
+ <url>http://noserver/jenkins/</url>
+ </ciManagement>
+ <scm>
+ <developerConnection>scm:svn:http://noserver</developerConnection>
+ <url>http://noserver</url>
+ </scm>
+ <dependencies>
+ <dependency>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ <version>1.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>c3p0</groupId>
+ <artifactId>c3p0</artifactId>
+ <version>0.9.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.1_3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <version>1.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.2.130</version>
+ </dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>javatar</groupId>
+ <artifactId>javatar</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>jpos</groupId>
+ <artifactId>jpos</artifactId>
+ <version>1.12.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jpos</groupId>
+ <artifactId>jpos-controls</artifactId>
+ <version>1.12.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.python</groupId>
+ <artifactId>jython</artifactId>
+ <version>2.5.2b2</version>
+ </dependency>
+ <dependency>
+ <groupId>urbanophile</groupId>
+ <artifactId>java-getopt</artifactId>
+ <version>1.0.13</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ibatis</groupId>
+ <artifactId>ibatis-sqlmap</artifactId>
+ <version>2.3.4.726</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-core</artifactId>
+ <version>2.0.0-M6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.dbunit</groupId>
+ <artifactId>dbunit</artifactId>
+ <version>2.4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-continuation</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-http</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-io</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-xml</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.2</version>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-test</artifactId>
+ <version>2.0.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-core</artifactId>
+ <version>2.0.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-infrastructure</artifactId>
+ <version>2.0.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springmodules</groupId>
+ <artifactId>spring-modules-cache</artifactId>
+ <version>0.9</version>
+ </dependency>
+ <dependency>
+ <groupId>p6spy</groupId>
+ <artifactId>p6spy</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.0.1B</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>com.caucho</groupId>
+ <artifactId>hessian</artifactId>
+ <version>3.1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jettison</groupId>
+ <artifactId>jettison</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.thoughtworks.xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ini4j</groupId>
+ <artifactId>ini4j</artifactId>
+ <version>0.5.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.4</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>dtgjpos_forms</groupId>
+ <artifactId>dtgjpos_forms</artifactId>
+ <version>1.4.12</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.castor</groupId>
+ <artifactId>castor-xml</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xmlbeans</groupId>
+ <artifactId>xmlbeans</artifactId>
+ <version>2.5.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity.tools</groupId>
+ <artifactId>velocity-tools-generic</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.tmatesoft.svnkit</groupId>
+ <artifactId>svnkit</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <modules>
+ <module>spring-aop-example</module>
+ </modules>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ <!-- Usually you will not need this plugin
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.6</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.2</version>
+ <configuration>
+ <testFailureIgnore>true</testFailureIgnore>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jdepend-maven-plugin</artifactId>
+ <version>2.0-beta-2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Specification-Title>${project.description}</Specification-Title>
+ <Specification-Version>${project.version}</Specification-Version>
+ <Specification-Vendor>${project.organization.name}</Specification-Vendor>
+ <Implementation-Title>${project.description}</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
+ <Implementation-Build>${BUILD_TAG}</Implementation-Build>
+ <Implementation-Build-id>${BUILD_ID}</Implementation-Build-id>
+ <Implementation-Build-number>${BUILD_NUMBER}</Implementation-Build-number>
+ <scm-committed-revision>${prefix.committedRevision}</scm-committed-revision>
+ <scm-repository>${prefix.repository}</scm-repository>
+ <scm-path>${prefix.path}</scm-path>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
+ <artifactId>maven-svn-revision-number-plugin</artifactId>
+ <version>1.6</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>revision</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <entries>
+ <entry>
+ <prefix>prefix</prefix>
+ </entry>
+ </entries>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <!--We need this for the javadoc and reporting maven plugin -->
+ <distributionManagement>
+ <repository>
+ <id>releases</id>
+ <name>releases</name>
+ <url>http://noserver/artifactory/custom-annotations-libs-releases-local</url>
+ </repository>
+ <snapshotRepository>
+ <id>snapshots-releases</id>
+ <name>snapshots-releases</name>
+ <url>http://noserver/artifactory/custom-annotations-libs-snapshots-local</url>
+ </snapshotRepository>
+ <site>
+ <id>noserver</id>
+ <url>file:///mnt/sdb1/data/downloads/jenkins/</url>
+ </site>
+
+ </distributionManagement>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.1.2</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>index</report>
+ <report>dependencies</report>
+ <report>cim</report>
+ <report>issue-tracking</report>
+ <report>scm</report>
+ <report>summary</report>
+ <report>project-team</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.6.1</version>
+ <reportSets>
+ <reportSet>
+ <id>html</id>
+ <configuration>
+ <doctitle>MYPROJECT API for ${project.name} ${project.version}</doctitle>
+ <windowtitle>MYPROJECT API for ${project.name} ${project.version}</windowtitle>
+ </configuration>
+ <reports>
+ <report>javadoc</report>
+ <report>aggregate</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>taglist-maven-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <tags>
+ <tag>TODO</tag>
+ <tag>@todo</tag>
+ <tag>FIXME</tag>
+ <tag>XXX</tag>
+ </tags>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <version>2.4.3</version>
+ <reportSets>
+ <reportSet>
+ <id>integration-tests</id>
+ <reports>
+ <report>report-only</report>
+ </reports>
+ <configuration>
+ <outputName>failsafe-report</outputName>
+ <reportsDirectories>
+ <reportsDirectory>target/failsafe-reports</reportsDirectory>
+ </reportsDirectories>
+ </configuration>
+ </reportSet>
+ <reportSet>
+ <id>junit-tests</id>
+ <reports>
+ <report>report-only</report>
+ </reports>
+ <configuration>
+ <outputName>surefire-report</outputName>
+ <reportsDirectories>
+ <reportsDirectory>target/surefire-reports</reportsDirectory>
+ </reportsDirectories>
+ </configuration>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <spring.version>2.5.6</spring.version>
+ </properties>
+ <repositories>
+ <!--
+ <repository>
+ <id>central-myproject-repo</id>
+ <name>Internal repository</name>
+ <url>http://noserver/artifactory/my-repo</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots-releases</id>
+ <name>snapshots-releases</name>
+ <url>http://noserver/artifactory/custom-annotations-libs-snapshots-local</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ -->
+ </repositories>
+ <pluginRepositories>
+ <!--
+ <pluginRepository>
+ <id>central-myproject-plugins-repo</id>
+ <name>Plugins internal repository</name>
+ <url>http://noserver/artifactory/plugins-repo</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </pluginRepository>
+ -->
+ </pluginRepositories>
+</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>spring-aop</artifactId>
+ <groupId>de.spring.example</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>spring-aop-example</artifactId>
+ <name>spring-aop-example</name>
+ <url>http://maven.apache.org</url>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aspects</artifactId>
+ <version>2.5.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+package de.spring.example;
+
+
+/**
+ *
+ * This class is not using the AspectJ annotations, so we could use it on JDK 1.4 and below.
+ * If we want to use it as an Aspect we may JUST do it using a schema based declaration.
+ * What means, you can use this class as an Aspect JUST using an xml Spring declaration.
+ *
+ */
+public class GeneralAccess {
+
+ public void monitor()
+ {
+ System.out.println("I am the Advice monitor for TestB and I will be run before.");
+ }
+}
--- /dev/null
+package de.spring.example;
+
+import java.lang.reflect.Method;
+import org.springframework.aop.MethodBeforeAdvice;
+
+/**
+ *
+ * We are using here an Advice of Spring 1.2
+ * See: http://static.springsource.org/spring/docs/3.1.0.RC1/spring-framework-reference/html/aop-api.html#aop-api-advice-types
+ *
+ */
+public class SpringAdvice implements MethodBeforeAdvice {
+
+ public void before(Method m, Object[] args, Object target) throws Throwable {
+ System.out.println("I am the SpringAdvice and I will be run before.");
+ }
+
+}
--- /dev/null
+package de.spring.example;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+/**
+ *
+ */
+public final class SpringContextLocator {
+
+ // Singleton Pattern
+ private static SpringContextLocator instance;
+
+ // Spring ApplicationContext
+ private static ApplicationContext context;
+
+ // Spring Context
+ private static final String SPRING_CONFIG_CONTEXT="spring-config.xml";
+
+
+ /**
+ * Private constructor. Singleton pattern.
+ */
+ private SpringContextLocator() {
+ String[] factoryFiles = null;
+ System.out.println("Loading context files: " + SpringContextLocator.SPRING_CONFIG_CONTEXT);
+
+ factoryFiles = new String[] { SPRING_CONFIG_CONTEXT };
+
+ SpringContextLocator.context = new ClassPathXmlApplicationContext(factoryFiles);
+
+ System.out.println("The context has been loaded successfully!! ");
+ }
+
+ /**
+ * Singleton pattern not thread safety. To use SingletoHolder pattern as the best approximation
+ * otherwise to use an Enum class (see Effective Java Second Edition and ) if we need serialization.
+ */
+ public static SpringContextLocator getInstance() {
+ if (SpringContextLocator.instance == null) {
+ SpringContextLocator.instance = new SpringContextLocator();
+ }
+ return SpringContextLocator.instance;
+ }
+
+ /**
+ * Return bean from application context.
+ */
+ public Object getBean(final String name) {
+ return SpringContextLocator.context.getBean(name);
+ }
+}
\ No newline at end of file
--- /dev/null
+package de.spring.example;
+
+import de.spring.example.service.TestB;
+import de.spring.example.web.TestA;
+
+public class SpringStart {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ System.out.println("Starting application");
+ SpringContextLocator.getInstance();
+
+ TestA testA = (TestA) SpringContextLocator.getInstance().getBean("testA");
+ testA.myMethod();
+
+ TestB testB = (TestB) SpringContextLocator.getInstance().getBean("testB");
+ testB.myMethod();
+ }
+}
--- /dev/null
+package de.spring.example;
+
+import org.aspectj.lang.annotation.Pointcut;
+
+/**
+ *
+ * Using the @Aspect annotation you could use this class as an Aspect without
+ * using a schema based declaration (without using <aop:aspect in the Spring xml file)
+ * What means, you could use this class as an Aspect without the xml Spring declaration.
+ *
+ */
+public class SystemArchitecture {
+
+ //Coonecting to the execution of any method defined in the
+ //package: de.spring.example.web
+ //We are connecting the methods defined in that package with this
+ //Pointcut. So, when executing any of those methods defined in that
+ //package we will run the Advice related to this Pointcut (if there is an Advice)
+ //NOTICE:
+ // WE ARE NOT USING THE @Aspect ANNOTATION, SO WE CAN USE THIS CLASS AS
+ // AN ASPECT AND THIS METHOD AS A POINTCUT JUST USING A SCHEMA BASED DECLARATION
+ @Pointcut("execution(* de.spring.example.web.*.*(..))")
+ public void pointCutMethod()
+ {
+ System.out.println("I am the Pointcut and you will never see me.");
+ //This is the PointCut.
+ //You can write code here, but it will be useless because while running
+ //the methods connected to the Pointcut, this code will not be executed.
+ //Just the advice will run!!!! :/
+ //Is not this weird? We are here defining a method whose code
+ //will never be run. When the hell should we write code here?
+ //This is a waste of time and code IMHO. Isn't it?
+ }
+
+ public void monitor()
+ {
+ System.out.println("I am the Advice monitor for TestA and I will be run before.");
+ }
+}
\ No newline at end of file
--- /dev/null
+package de.spring.example.service;
+
+public class TestB {
+ public int myMethod()
+ {
+ System.out.println("TestB: The Advice should be run before.");
+
+ //This value will be caught by the Advice with the @AfterReturning annotation.
+ return 999;
+ }
+}
--- /dev/null
+package de.spring.example.web;
+
+
+public class TestA {
+ public int myMethod()
+ {
+ System.out.println("TestA: The Advice should be run before.");
+
+ //This value will be caught by the Advice with the @AfterReturning annotation.
+ return 666;
+ }
+}
--- /dev/null
+<?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-2.5.xsd
+ http://www.springframework.org/schema/aop
+ http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-2.5.xsd
+ http://www.springframework.org/schema/tx
+ http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+
+ <!--
+ To force CGLIB proxying when using Spring AOP
+ See: http://static.springsource.org/spring/docs/3.1.0.RC1/spring-framework-reference/html/aop.html#aop-proxying
+ -->
+ <aop:config proxy-target-class="true">
+ <aop:aspect id="myAspectSchemaBased" ref="generalAccess">
+ <aop:pointcut id="aspectOperation"
+ expression="execution(* de.spring.example.service.*.*(..))"/>
+ <aop:before pointcut-ref="aspectOperation" method="monitor"/>
+ </aop:aspect>
+ </aop:config>
+
+
+ <aop:config proxy-target-class="true">
+ <aop:aspect id="myAspectwithAnnotations" ref="systemArchitecture">
+ <!--
+ See: http://static.springsource.org/spring/docs/3.1.0.RC1/spring-framework-reference/html/aop.html#aop-schema-pointcuts
+ "Note that the pointcut expression itself is using the same AspectJ pointcut expression
+ language as described in Section 8.2, “@AspectJ support”. If you are using the schema
+ based declaration style with Java 5, you can refer to named pointcuts defined in types
+ (@Aspects) within the pointcut expression, but this feature is not available on JDK 1.4 and below
+ (it relies on the Java 5 specific AspectJ reflection APIs). On JDK 1.5 therefore, another way of
+ defining the above pointcut would be:
+ -->
+ <aop:pointcut id="pointCutAspect"
+ expression="de.spring.example.SystemArchitecture.pointCutMethod()"/>
+ <!-- This will be the Advice. You can use the same class for it or you can use the aop:advisor
+ xml Spring annotation. In that case you have to use an Advice class from AOP support of Spring 1.2
+ (below you can see an example of this)
+ -->
+ <aop:before pointcut-ref="pointCutAspect" method="monitor"/>
+ </aop:aspect>
+ </aop:config>
+
+
+ <!--
+ We are using AOP support from Spring 1.2 :/ for this Advice
+ (we use Spring beans as advices and we can use the AOP support from Spring 1.2 for this)
+ We can use and mix whatever we want. Spring is powerful but at the same time it can be a complete mess.
+ -->
+ <aop:config proxy-target-class="true">
+ <aop:advisor pointcut="de.spring.example.SystemArchitecture.pointCutMethod()"
+ advice-ref="springAdvice" />
+ </aop:config>
+
+ <bean id="testA" class="de.spring.example.web.TestA">
+
+ </bean>
+
+ <bean id="testB" class="de.spring.example.service.TestB">
+
+ </bean>
+
+ <bean id="generalAccess" class="de.spring.example.GeneralAccess">
+
+ </bean>
+
+ <bean id="systemArchitecture" class="de.spring.example.SystemArchitecture">
+
+ </bean>
+
+ <bean id="springAdvice" class="de.spring.example.SpringAdvice">
+
+ </bean>
+
+</beans>
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
<modelVersion>4.0.0</modelVersion>
<groupId>de.spring.example</groupId>
<artifactId>spring-aspectj</artifactId>
<version>2.0-SNAPSHOT</version>
- <name>custom-annotations</name>
- <url>http://maven.apache.org</url>
+ <name>spring-aspect</name>
+ <url>http://www.myorganization.de</url>
+ <description>Spring AspectJ with Spring Libraries</description>
+ <organization>
+ <name>MyOrganization</name>
+ <url>http://www.myorganization.de</url>
+ </organization>
<packaging>pom</packaging>
-
+ <issueManagement>
+ <system>trac</system>
+ <url>http://noserver/</url>
+ </issueManagement>
+ <ciManagement>
+ <system>jenkins</system>
+ <url>http://noserver/jenkins/</url>
+ </ciManagement>
+ <scm>
+ <developerConnection>scm:svn:http://noserver</developerConnection>
+ <url>http://noserver</url>
+ </scm>
<dependencies>
+ <dependency>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ <version>1.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>c3p0</groupId>
+ <artifactId>c3p0</artifactId>
+ <version>0.9.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.1_3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <version>1.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.2.130</version>
+ </dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>javatar</groupId>
+ <artifactId>javatar</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>jpos</groupId>
+ <artifactId>jpos</artifactId>
+ <version>1.12.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jpos</groupId>
+ <artifactId>jpos-controls</artifactId>
+ <version>1.12.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.python</groupId>
+ <artifactId>jython</artifactId>
+ <version>2.5.2b2</version>
+ </dependency>
+ <dependency>
+ <groupId>urbanophile</groupId>
+ <artifactId>java-getopt</artifactId>
+ <version>1.0.13</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ibatis</groupId>
+ <artifactId>ibatis-sqlmap</artifactId>
+ <version>2.3.4.726</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-core</artifactId>
+ <version>2.0.0-M6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.dbunit</groupId>
+ <artifactId>dbunit</artifactId>
+ <version>2.4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-continuation</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-http</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-io</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-xml</artifactId>
+ <version>7.0.0.v20091005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.2</version>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-test</artifactId>
+ <version>2.0.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-core</artifactId>
+ <version>2.0.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-infrastructure</artifactId>
+ <version>2.0.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springmodules</groupId>
+ <artifactId>spring-modules-cache</artifactId>
+ <version>0.9</version>
+ </dependency>
+ <dependency>
+ <groupId>p6spy</groupId>
+ <artifactId>p6spy</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.0.1B</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>com.caucho</groupId>
+ <artifactId>hessian</artifactId>
+ <version>3.1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jettison</groupId>
+ <artifactId>jettison</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.thoughtworks.xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ini4j</groupId>
+ <artifactId>ini4j</artifactId>
+ <version>0.5.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>dtgjpos_forms</groupId>
+ <artifactId>dtgjpos_forms</artifactId>
+ <version>1.4.12</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.castor</groupId>
+ <artifactId>castor-xml</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xmlbeans</groupId>
+ <artifactId>xmlbeans</artifactId>
+ <version>2.5.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity.tools</groupId>
+ <artifactId>velocity-tools-generic</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.tmatesoft.svnkit</groupId>
+ <artifactId>svnkit</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
<modules>
- <module>spring-aspectj-example</module>
+ <module>spring-aspectj-example</module>
</modules>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ <!-- Usually you will not need this plugin
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.6</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.2</version>
+ <configuration>
+ <testFailureIgnore>true</testFailureIgnore>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jdepend-maven-plugin</artifactId>
+ <version>2.0-beta-2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Specification-Title>${project.description}</Specification-Title>
+ <Specification-Version>${project.version}</Specification-Version>
+ <Specification-Vendor>${project.organization.name}</Specification-Vendor>
+ <Implementation-Title>${project.description}</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
+ <Implementation-Build>${BUILD_TAG}</Implementation-Build>
+ <Implementation-Build-id>${BUILD_ID}</Implementation-Build-id>
+ <Implementation-Build-number>${BUILD_NUMBER}</Implementation-Build-number>
+ <scm-committed-revision>${prefix.committedRevision}</scm-committed-revision>
+ <scm-repository>${prefix.repository}</scm-repository>
+ <scm-path>${prefix.path}</scm-path>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
+ <artifactId>maven-svn-revision-number-plugin</artifactId>
+ <version>1.6</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>revision</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <entries>
+ <entry>
+ <prefix>prefix</prefix>
+ </entry>
+ </entries>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <!--We need this for the javadoc and reporting maven plugin -->
+ <distributionManagement>
+ <repository>
+ <id>releases</id>
+ <name>releases</name>
+ <url>http://noserver/artifactory/custom-annotations-libs-releases-local</url>
+ </repository>
+ <snapshotRepository>
+ <id>snapshots-releases</id>
+ <name>snapshots-releases</name>
+ <url>http://noserver/artifactory/custom-annotations-libs-snapshots-local</url>
+ </snapshotRepository>
+ <site>
+ <id>noserver</id>
+ <url>file:///mnt/sdb1/data/downloads/jenkins/</url>
+ </site>
+
+ </distributionManagement>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>2.1.2</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>index</report>
+ <report>dependencies</report>
+ <report>cim</report>
+ <report>issue-tracking</report>
+ <report>scm</report>
+ <report>summary</report>
+ <report>project-team</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.6.1</version>
+ <reportSets>
+ <reportSet>
+ <id>html</id>
+ <configuration>
+ <doctitle>MYPROJECT API for ${project.name} ${project.version}</doctitle>
+ <windowtitle>MYPROJECT API for ${project.name} ${project.version}</windowtitle>
+ </configuration>
+ <reports>
+ <report>javadoc</report>
+ <report>aggregate</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>taglist-maven-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <tags>
+ <tag>TODO</tag>
+ <tag>@todo</tag>
+ <tag>FIXME</tag>
+ <tag>XXX</tag>
+ </tags>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <version>2.4.3</version>
+ <reportSets>
+ <reportSet>
+ <id>integration-tests</id>
+ <reports>
+ <report>report-only</report>
+ </reports>
+ <configuration>
+ <outputName>failsafe-report</outputName>
+ <reportsDirectories>
+ <reportsDirectory>target/failsafe-reports</reportsDirectory>
+ </reportsDirectories>
+ </configuration>
+ </reportSet>
+ <reportSet>
+ <id>junit-tests</id>
+ <reports>
+ <report>report-only</report>
+ </reports>
+ <configuration>
+ <outputName>surefire-report</outputName>
+ <reportsDirectories>
+ <reportsDirectory>target/surefire-reports</reportsDirectory>
+ </reportsDirectories>
+ </configuration>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <spring.version>2.5.6</spring.version>
+ </properties>
+ <repositories>
+ <!--
+ <repository>
+ <id>central-myproject-repo</id>
+ <name>Internal repository</name>
+ <url>http://noserver/artifactory/my-repo</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots-releases</id>
+ <name>snapshots-releases</name>
+ <url>http://noserver/artifactory/custom-annotations-libs-snapshots-local</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ -->
+ </repositories>
+ <pluginRepositories>
+ <!--
+ <pluginRepository>
+ <id>central-myproject-plugins-repo</id>
+ <name>Plugins internal repository</name>
+ <url>http://noserver/artifactory/plugins-repo</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </pluginRepository>
+ -->
+ </pluginRepositories>
</project>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
<modelVersion>4.0.0</modelVersion>
-
<parent>
<artifactId>spring-aspectj</artifactId>
<groupId>de.spring.example</groupId>
<version>2.0-SNAPSHOT</version>
</parent>
- <groupId>de.spring.example</groupId>
<artifactId>spring-aspectj-example</artifactId>
- <version>2.0-SNAPSHOT</version>
<name>spring-aspectj-example</name>
<url>http://maven.apache.org</url>
<dependencies>
-
- <!-- Assembly version info -->
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-model</artifactId>
- <version>2.2.1</version>
- </dependency>
-
- <!--
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aspects</artifactId>
- <version>2.5.6</version>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aspects</artifactId>
+ <version>2.5.6</version>
</dependency>
- -->
-
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
- <version>2.5.6</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- <version>2.5.6</version>
- </dependency>
-
- <dependency>
- <groupId>c3p0</groupId>
- <artifactId>c3p0</artifactId>
- <version>0.9.1.2</version>
</dependency>
-
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>1.6.12</version>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
</dependency>
-
<dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjweaver</artifactId>
- <version>1.6.12</version>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
</dependency>
-
- <!--
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-agent</artifactId>
- <version>2.5.6</version>
- </dependency>
- -->
-
</dependencies>
-
</project>
--- /dev/null
+package de.spring.example;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+
+@Aspect
+public class MyAdvice {
+
+ //This advice is connected with the Pointcut defined in SystemArchitecture.
+ //So, every method connected to that Pointcut will be run after the
+ //method defined in this Advice.
+ @Before("de.spring.example.SystemArchitecture.pointCutMethod())")
+ public void doAccessCheck() {
+ System.out.println("I am the Advice and I will be run before.");
+ }
+}
--- /dev/null
+package de.spring.example;
+
+import java.lang.reflect.Method;
+import org.springframework.aop.MethodBeforeAdvice;
+
+/**
+ *
+ * We are using here an Advice of Spring 1.2
+ * See: http://static.springsource.org/spring/docs/3.1.0.RC1/spring-framework-reference/html/aop-api.html#aop-api-advice-types
+ *
+ */
+public class SpringAdvice implements MethodBeforeAdvice {
+
+ public void before(Method m, Object[] args, Object target) throws Throwable {
+ System.out.println("I am the SpringAdvice and I will be run before.");
+ }
+
+}
--- /dev/null
+package de.spring.example;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+/**
+ *
+ */
+public final class SpringContextLocator {
+
+ // Singleton Pattern
+ private static SpringContextLocator instance;
+
+ // Spring ApplicationContext
+ private static ApplicationContext context;
+
+ // Spring Context
+ private static final String SPRING_CONFIG_CONTEXT="spring-config.xml";
+
+
+ /**
+ * Private constructor. Singleton pattern.
+ */
+ private SpringContextLocator() {
+ String[] factoryFiles = null;
+ System.out.println("Loading context files: " + SpringContextLocator.SPRING_CONFIG_CONTEXT);
+
+ factoryFiles = new String[] { SPRING_CONFIG_CONTEXT };
+
+ SpringContextLocator.context = new ClassPathXmlApplicationContext(factoryFiles);
+
+ System.out.println("The context has been loaded successfully!! ");
+ }
+
+ /**
+ * Singleton pattern not thread safety. To use SingletoHolder pattern as the best approximation
+ * otherwise to use an Enum class (see Effective Java Second Edition and ) if we need serialization.
+ */
+ public static SpringContextLocator getInstance() {
+ if (SpringContextLocator.instance == null) {
+ SpringContextLocator.instance = new SpringContextLocator();
+ }
+ return SpringContextLocator.instance;
+ }
+
+ /**
+ * Return bean from application context.
+ */
+ public Object getBean(final String name) {
+ return SpringContextLocator.context.getBean(name);
+ }
+}
\ No newline at end of file
--- /dev/null
+package de.spring.example;
+
+import de.spring.example.web.Test;
+
+public class SpringStart {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ System.out.println("Starting application");
+ SpringContextLocator.getInstance();
+
+ Test test = (Test) SpringContextLocator.getInstance().getBean("test");
+ test.myMethod();
+ }
+}
--- /dev/null
+package de.spring.example;
+
+import org.aspectj.lang.annotation.AfterReturning;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+/**
+ *
+ * We are using here the @AspectJ annotations to declare
+ * Proxies. If we want to use these kinds of proxies on the Spring framework
+ * we have to use the <aop:aspectj-autoproxy/> annotation on the Spring xml file
+ * (the Spring context file)
+ */
+@Aspect
+public class SystemArchitecture {
+
+ //Coonecting to the execution of any method defined in the
+ //package: de.spring.example.web
+ //We are connecting the methods defined in that package with this
+ //Pointcut. So, when executing any of those methods defined in that
+ //package we will run the Advice related to this Pointcut (if there is an Advice)
+ @Pointcut("execution(* de.spring.example.web.*.*(..))")
+ public void pointCutMethod()
+ {
+ System.out.println("I am the Pointcut and you will never see me.");
+ //This is the PointCut.
+ //You can write code here, but it will be useless because while running
+ //the methods connected to the Pointcut, this code will not be executed.
+ //Just the advice will run!!!! :/
+ //Is not this weird? We are here defining a method whose code
+ //will never be run. When the hell should we write code here?
+ //This is a waste of time and code IMHO. Isn't it?
+ }
+
+ //NOTICE: YOU DO NOT NEED TO CREATE A SPECIAL CLASS FOR THE ADVICE
+ // YOU COULD USE THE SAME CLASS FOR THE POINTCUTS AND FOR THE
+ // ADVICES. IN THIS CASE FOR EXAMPLE WE HAVE THE @AfterReturning
+ // ADVICE IN THIS CLASS AND THE @Before ADVICE IN THE CLASS CALLED
+ // MyAdvice
+ //This advice is connected with the another Pointcut.
+ //The returning value of every method connected to that Pointcut
+ //will be caught by this method.
+ @AfterReturning(pointcut="de.spring.example.SystemArchitecture.pointCutMethod())",
+ returning="retVal")
+ public void doAccessCheck(final Object retVal) {
+ System.out.println("The returned value by the method " +
+ "connected to the Pointcut: " + retVal);
+ }
+}
\ No newline at end of file
--- /dev/null
+package de.spring.example.web;
+
+
+public class Test {
+ public int myMethod()
+ {
+ System.out.println("The Advice should be run before.");
+
+ //This value will be caught by the Advice with the @AfterReturning annotation.
+ return 666;
+ }
+}
+++ /dev/null
-package de.spring.example;
-
-import java.util.Map;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-
-public class AnnotationsHandler implements ApplicationContextAware, InitializingBean {
- private ApplicationContext applicationContext;
-
- @Override
- public void afterPropertiesSet() {
- GenericBeanFactoryAccessor genericBeanFactoryAccessor = new GenericBeanFactoryAccessor(applicationContext);
-
- final Map<String, Object> transactionalClass = genericBeanFactoryAccessor.getBeansWithAnnotation(TransactionalN2A.class);
-
- for (final Object myFoo : transactionalClass.values()) {
- final Class<? extends Object> fooClass = myFoo.getClass();
- final TransactionalN2A annotation = fooClass.getAnnotation(TransactionalN2A.class);
- System.out.println("Found 1 foo class: " + fooClass + ", with tags: ");
- }
- }
-
- @Override
- public void setApplicationContext(final ApplicationContext applicationContext)
- throws BeansException {
- this.applicationContext = applicationContext;
- }
- }
-
+++ /dev/null
-package de.spring.example;
-
-import java.util.Map;
-
-import org.aspectj.lang.annotation.Aspect;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-@Aspect
-public class AspectHandler {
-
-
-
-
- }
-
+++ /dev/null
-package de.spring.example;
-
-
-public class Prueba {
- public void bar(){
- System.out.println("I am not a number, I am a free man!");
- }
-
- @TransactionalN2A
- public class InnerService {
- public void innerMethod() {
- System.out.println("xxx: AopService$InnerClass.innerMethod()");
- }
- }
-
-}
-
+++ /dev/null
-package de.spring.example;
-
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-
-/**
- * Localizador de beans para de los dispositivos
- *
- * @author rvp001es
- */
-public final class SpringContextLocator {
-
-
- // Singleton Pattern
- private static SpringContextLocator instance;
-
- // Spring ApplicationContext
- private static ApplicationContext context;
-
- // Dispositivos logicos
- private static final String SPRING_CONFIG_CONTEXT="spring-config.xml";
- //private static final String DATABASE_CONFIG="database-config.xml";
-
-
- /**
- * Private constructor. Singleton pattern.
- */
- private SpringContextLocator() {
- String[] factoryFiles = null;
- System.out.println("Loading files context " +
- SpringContextLocator.SPRING_CONFIG_CONTEXT);
-
- factoryFiles = new String[] { SPRING_CONFIG_CONTEXT };
-
- SpringContextLocator.context = new ClassPathXmlApplicationContext(factoryFiles);
-
- System.out.println("The N2A devices context and test " +
- "context has been loaded successfully!! ");
- }
-
- /**
- * Singleton pattern. GetInstance()
- */
- public synchronized static SpringContextLocator getInstance() {
- if (SpringContextLocator.instance == null) {
- SpringContextLocator.instance = new SpringContextLocator();
- }
- return SpringContextLocator.instance;
- }
-
- /**
- * Return a bean in application context.
- */
- public Object getBean(final String name) {
- return SpringContextLocator.context.getBean(name);
- }
-}
+++ /dev/null
-package de.spring.example;
-
-public class SpringStart {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- System.out.println("HOLA");
- SpringContextLocator.getInstance();
-
- }
-
-}
+++ /dev/null
-package de.spring.example;
-
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-import org.springframework.transaction.TransactionStatus;
-
-
-public class TransactionManagerN2A {
- private static TransactionManagerN2A instance = new TransactionManagerN2A();
- private DataSourceTransactionManager transactionManager;
- private TransactionStatus transactionStatus;
-
- //Why could you want to extend this class?
- private TransactionManagerN2A() {}
-
- public static TransactionManagerN2A getInstance() {
- return instance;
- }
-
- public void initTransaction()
- {
- transactionStatus = this.transactionManager.getTransaction(null);
- }
-
- public void rollbackTransaction()
- {
- this.transactionManager.rollback(this.transactionStatus);
- }
-
- public void commitTransaction()
- {
- this.transactionManager.commit(this.transactionStatus);
- }
-
-
- /************************* Setters and getters *******************************************/
- public void setTransactionManager(final DataSourceTransactionManager transactionManager)
- {
- this.transactionManager = transactionManager;
- }
-}
-
+++ /dev/null
-/**
- *
- */
-package de.spring.example;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import org.springframework.stereotype.Component;
-
-
-@Retention(RetentionPolicy.RUNTIME)
-@Component
-public @interface TransactionalN2A {
-}
+++ /dev/null
-<!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="es.dia.*"/>
- </weaver>
- <aspects>
- <aspect name="es.dia.pos.n2a.aspectj.annotations.AnnotationsHandler"/>
- </aspects>
- </aspectj>
\ No newline at end of file
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
-
- <aop:aspectj-autoproxy proxy-target-class="true"/>
-
- <context:load-time-weaver
- weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"
- aspectj-weaving="on"/>
-
-
- <context:component-scan base-package="es.dia">
- <context:include-filter
- type="annotation"
- expression="es.dia.pos.n2a.aspectj.annotations.TransactionalN2A" />
- </context:component-scan>
-
-
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
- <property name="user" value="root"/>
- <property name="password" value=""/>
- <property name="driverClass" value="com.mysql.jdbc.Driver"/>
- <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/n2a?autoReconnect=true"/>
- <property name="initialPoolSize" value="5"/>
- <property name="maxPoolSize" value="20"/>
- <property name="minPoolSize" value="10"/>
- <property name="acquireIncrement" value="1"/>
- <property name="acquireRetryAttempts" value="5"/>
- <property name="acquireRetryDelay" value="1000"/>
- <property name="automaticTestTable" value="con_test"/>
- <property name="checkoutTimeout" value="5000"/>
- </bean>
- <bean id="annotationsHandler" class="es.dia.pos.n2a.aspectj.annotations.AnnotationsHandler" >
+ <!--
+ ************* WE HAVE TO ENABLE THE ASPECTJ SUPPORT!!!!!! *************
+ Otherwise the @Aspect annotation (defines @AspectJ aspects) will not work
+ It relies on the Java 5 specific AspectJ reflection APIs. You can not use it on
+ JDK 1.4 and below.
+
+
+ We could force here the use of CGLIB.
+ See: http://static.springsource.org/spring/docs/3.1.0.RC1/spring-framework-reference/html/aop.html#aop-proxying
+ Spring detects if the bean has an interface implementation. If it has one, Spring will use J2SE
+ (J2SE needs classes with interfaces) in other case it will use CGLIB.
+ In this example the "test" bean does not have an interface so Spring
+ will use CGLIB. We could force the use of CGLIB in classes with interfaces.
+ -->
+ <aop:aspectj-autoproxy/>
- </bean>
+ <!--
+ We can mix aspect types. Without this AOP declaration this project would be SPRING ASPECTJ
+ but, because of this, we have a Spring Advice declaration so this project will be a SPRING AOP project
+ (or at least it is not just SPRING ASPECTJ based)
+ Besides we are using AOP support used in Spring 1.2 :/
+ -->
+ <aop:config proxy-target-class="true">
+ <aop:advisor pointcut="de.spring.example.SystemArchitecture.pointCutMethod()"
+ advice-ref="springAdvice" />
+ </aop:config>
- <!--
- <bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf">
- <property name="transactionManagerN2A" ref="transactionManagerN2A"/>
- </bean>
- -->
-
- <bean id="pruebaOuter" class="es.dia.pos.n2a.aspectj.annotations.Prueba"/>
- <bean id="pruebaInner" class="es.dia.pos.n2a.aspectj.annotations.Prueba$InnerService">
- <constructor-arg ref="pruebaOuter"/>
+
+ <bean id="test" class="de.spring.example.web.Test">
+
</bean>
- <!--
- I do not care about the N2A default configuration, so I use here the scope singleton and lazy-init false.
- -->
- <bean id="transactionManagerN2A"
- class="es.dia.pos.n2a.aspectj.annotations.TransactionManagerN2A"
- factory-method="getInstance"
- scope="singleton"
- lazy-init="false" >
- <property name="transactionManager">
- <ref bean="transactionManager" />
- </property>
+ <bean id="myAdvice" class="de.spring.example.MyAdvice">
+
</bean>
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"/>
+ <bean id="systemArchitecture" class="de.spring.example.SystemArchitecture">
+
</bean>
-
+
+ <bean id="springAdvice" class="de.spring.example.SpringAdvice">
+
+ </bean>
+
</beans>