Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Below is the sample example i had tried to test spring AOP.</p> <p><strong>SpringConfig.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd "&gt; &lt;bean id="beanPostProcessor" class="springTest.SpringBeanPostProcessor" /&gt; &lt;bean id="contestPostProcessor" class="springTest.SpringPostProcessor" /&gt; &lt;bean id="emp" class="springTest.Employee"&gt; &lt;property name="id" value="1"/&gt; &lt;property name="name" value="sunil"/&gt; &lt;/bean&gt; &lt;bean id="loginCheckAspect" class="springTest.Aspect" init-method="initAspect"/&gt; &lt;bean id="msg" class="springTest.LoadMessages" &gt; &lt;property name="id" value="1" /&gt; &lt;/bean&gt; &lt;aop:config&gt; &lt;aop:pointcut id="login" expression="execution(* *.showMsg*(..))"/&gt; &lt;aop:aspect id="loginAspect" ref="loginCheckAspect" &gt; &lt;aop:before method="checkLogin" pointcut-ref="login" /&gt; &lt;/aop:aspect&gt; &lt;/aop:config&gt; &lt;/beans&gt; </code></pre> <p><strong>LoadMessages.class</strong></p> <pre><code>package springTest; public class LoadMessages { int id; public int getId() { return id; } public void setId(int id) { this.id = id; } public LoadMessages() { } public void showMsg(){ System.out.println("#################################################"); System.out.println("Welcome neel"); System.out.println(); } public void getInfo(){ System.out.println("#################################################"); System.out.println("Welcome neel"); System.out.println(); } } </code></pre> <p><strong>Aspect.java</strong></p> <pre><code>package springTest; import java.io.DataInputStream; import java.io.IOException; public class Aspect { public void checkLogin() throws IOException{ DataInputStream ds=new DataInputStream(System.in); //BufferedInputStream bf=new BufferedInputStream(System.in); System.out.println("\n\n** Credential Check Point using AOP login aspect ** "); System.out.print("Please login to view employee details"); System.out.print("\nUser Name : "); String userName=ds.readLine(); String pass; if(userName!=null &amp;&amp; userName.equals("neel")){ System.out.print("Password : "); pass=ds.readLine(); if(pass!=null &amp;&amp; pass.equals("77")){ System.out.println(); }else{ throw new IOException("Invalid Password"); } }else{ throw new IOException("Invalid User Name"); } } public void initAspect(){ //System.out.println("@@@@@@ Init method of aspect @@@@@"); } } </code></pre> <p><strong>SpringBeanPostProcessor.java</strong></p> <pre><code>package springTest; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; public class SpringBeanPostProcessor implements BeanPostProcessor { public Object postProcessAfterInitialization(Object arg0, String arg1) throws BeansException { System.out.println("Initialization Completes "+arg1); return arg0; } public Object postProcessBeforeInitialization(Object arg0, String arg1) throws BeansException { System.out.println("Initialization...."); return arg0; } } </code></pre> <p><strong>SpringPostProcessor.java</strong></p> <pre><code>package springTest; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; public class SpringPostProcessor implements BeanFactoryPostProcessor { public void postProcessBeanFactory(ConfigurableListableBeanFactory arg0) throws BeansException { System.out.println("Initialization Context Succssefull."); } } </code></pre> <p>Hope this will help you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload