I am creating a simple program to learn AOP, but AOP is not getting applied to my program.
My configuration file is helloAop.xml:
GreetingServiceImpl Java file is:PHP Code:<?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
[url]http://www.springframework.org/schema/beans/spring-beans-2.0.xsd[/url]
[url]http://www.springframework.org/schema/aop[/url]
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="greetingService"
class="com.springinaction.chapter01.helloAop.GreetingServiceImpl">
<property name="greeting" value="Hello World!" />
</bean>
<bean id="aopbean" class="com.springinaction.chapter01.helloAop.AopBean" />
<aop:config>
<aop:aspect ref="aopbean">
<aop:pointcut id="samplePointcut" expression="execution(* *.sayGreeting(..))" />
<aop:before method="sampleBefore" pointcut-ref="samplePointcut" />
<aop:after-returning method="sampleAfter"
pointcut-ref="samplePointcut" />
</aop:aspect>
</aop:config>
</beans>
My program to access bean from configuration file is HelloApp.java:PHP Code:package com.springinaction.chapter01.helloAop;
public class GreetingServiceImpl implements GreetingService {
private String greeting;
public GreetingServiceImpl() {
}
public GreetingServiceImpl(String greeting) {
this.greeting = greeting;
}
public void sayGreeting() {
System.out.println(greeting);
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
When I am running HelloApp.java file I am getting below output:PHP Code:package com.springinaction.chapter01.helloAop;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class HelloApp {
public static void main(String[] args) throws Exception {
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"helloAop.xml"));
GreetingService greetingService = (GreetingService) factory
.getBean("greetingService");
greetingService.sayGreeting();
}
}
AOP is not getting applied to GreetingServiceImple bean, please help me in solving my issue.PHP Code:Feb 22, 2013 3:37:22 PM org.springframework.core.CollectionFactory <clinit>
INFO: JDK 1.4+ collections available
Feb 22, 2013 3:37:22 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [D:\Chaitanya\Others\Learning\Workspaces\Spring\SpringExamples1\helloAop.xml]
Hello World!


Reply With Quote