Skip to content
Browse files

Initial commit.

  • Loading branch information...
0 parents commit dc5ddb8baa41be948d6d2bea99c9ea4b9d0670ad @davelnewton committed Dec 1, 2011
5 .gitignore
@@ -0,0 +1,5 @@
+.idea/
+target/
+tmp/
+*.iml
+.git/
77 pom.xml
@@ -0,0 +1,77 @@
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>maven01</groupId>
+ <artifactId>maven01</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+
+ <name>foo.bar</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>3.0.6.RELEASE</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>3.0.6.RELEASE</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>3.0.6.RELEASE</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aspects</artifactId>
+ <version>3.0.6.RELEASE</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>1.6.12</version>
+ </dependency>
+
+ <dependency>
+ <groupId>aopalliance</groupId>
+ <artifactId>aopalliance</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2.2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <mainClass>maven01.App</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
18 src/main/java/foo.bar/AnException.java
@@ -0,0 +1,18 @@
+package foo.bar;
+
+public class AnException extends Exception {
+ public AnException() {
+ }
+
+ public AnException(String s) {
+ super(s);
+ }
+
+ public AnException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
+
+ public AnException(Throwable throwable) {
+ super(throwable);
+ }
+}
18 src/main/java/foo.bar/AnotherException.java
@@ -0,0 +1,18 @@
+package foo.bar;
+
+public class AnotherException extends Exception {
+ public AnotherException() {
+ }
+
+ public AnotherException(String s) {
+ super(s);
+ }
+
+ public AnotherException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
+
+ public AnotherException(Throwable throwable) {
+ super(throwable);
+ }
+}
22 src/main/java/foo.bar/App.java
@@ -0,0 +1,22 @@
+package foo.bar;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class App {
+
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+
+ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config.xml");
+
+ ThrowingClass tc = (ThrowingClass) ctx.getBean("tc");
+ try {
+ tc.foo();
+ } catch (AnException e) {
+ e.printStackTrace();
+ } catch (AnotherException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
7 src/main/java/foo.bar/LogException.java
@@ -0,0 +1,7 @@
+package foo.bar;
+
+public class LogException {
+ public void logIt(AnException ex) {
+ System.out.println("*** " + ex.getMessage());
+ }
+}
15 src/main/java/foo.bar/ThrowingClass.java
@@ -0,0 +1,15 @@
+package foo.bar;
+
+import java.util.Random;
+
+public class ThrowingClass {
+ public void foo() throws AnException, AnotherException {
+ System.out.println("In foo");
+ int rnd = new Random().nextInt(2);
+ if (rnd == 0) {
+ throw new AnException("rnd was 0");
+ } else {
+ throw new AnotherException("rnd wasn't 0");
+ }
+ }
+}
17 src/main/java/spring-config.xml
@@ -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: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/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
+
+ <bean name="tc" class="foo.bar.ThrowingClass"/>
+
+ <bean name="logex" class="foo.bar.LogException"/>
+
+ <aop:config>
+ <aop:aspect id="afterThrowingExample" ref="logex">
+ <aop:after-throwing method="logIt"
+ throwing="ex"
+ pointcut="execution(* foo.bar.*.foo(..))"/>
+ </aop:aspect>
+ </aop:config>
+</beans>

0 comments on commit dc5ddb8

Please sign in to comment.
Something went wrong with that request. Please try again.