- /**
- *
- */
- package com;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- /**
- * @author Administrator write Main.java at : 2007-6-6 涓婂崍08:53:23
- *
- */
- public class Main {
- public final static String name = "bean";
- /**
- * @param args
- */
- public static void main(String[] args) {
- // System.out.println(System.getProperties().toString());
- ApplicationContext ctx = new ClassPathXmlApplicationContext(
- "**/applicationContext.xml");
- /*
- Resource r = ctx.getResource("file:c:/aa.txt");
- String ss = "${user.dir}aaa";
- System.out.println(SystemPropertyUtils.resolvePlaceholders(ss));
- System.out.println(System.getProperties().toString());
- */
- Bean7 b = (Bean7) ctx.getBean("b7");
- b.transfer();
- // System.out.println(r.exists());
- /*
- * Mymethod b = (Mymethod) ctx.getBean("beanTarget");
- *
- * b.listPersons();
- */
- /*
- * for (int i = 1; i < 10; i++) { b.addPerson(i+"", i+""); }
- */
- /*
- * Bean7 b=(Bean7) ctx.getBean("b7");
- *
- *
- *
- * b.transfer();
- */
- /*String s = (String) ctx.getBean("myfactoryBean");
- Mymethod b = (Mymethod) ctx.getBean(name);
- b.addPerson("sss", "sss");
- b.listPersons();*/
- /*
- *
- *
- * Resource resource=ctx.getResource("file:jdbc.properties");
- *
- * System.out.println( resource.getFilename());
- *
- *
- *
- * try { BufferedInputStream bis=new
- * BufferedInputStream(resource.getInputStream()); byte[] s=new
- * byte[bis.available()];
- *
- *
- * bis.read(s);
- *
- *
- * System.out.println(new String(s)) ; } catch (IOException e) { // TODO
- * Auto-generated catch block e.printStackTrace(); }
- */
- /*
- * String[] s=new String[2];
- *
- * s[0]="ssss"; s[1]="00000";
- * System.out.println(ctx.getMessage("message", s,"ss",null) );
- *
- * NewBean nb=(NewBean) ctx.getBean("NewBean"); System.out.println(
- * nb.getB().getName());
- */
- /*
- * CommandManager commandManager=(CommandManager)
- * ctx.getBean("commandManager");
- *
- *
- * commandManager.process();
- */
- }
- }
- /**
- *
- */
- package com;
- import org.hibernate.SessionFactory;
- import org.springframework.orm.hibernate3.HibernateTemplate;
- import person.PersonModel;
- /**
- * @author Administrator write Bean.java at : 2007-6-6 涓婂崍08:56:16
- *
- */
- public class Bean7 {
- public void transfer()
- {
- System.out.println("transfering");
- }
- }
- package org.xyz;
- import org.aspectj.lang.ProceedingJoinPoint;
- public class NotVeryUsefulAspect {
- public void before(){
- System.out.println("before ");
- }
- public void after_returning(){
- System.out.println("after_returning");
- }
- public void after_throwing(){
- System.out.println("after_throwing");
- }
- public void around(ProceedingJoinPoint pjp) throws Throwable{
- System.out.println("around");
- pjp.proceed();
- }
- public int getOrder() {
- // TODO Auto-generated method stub
- return 1000;
- }
- }
- <?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:tx="http://www.springframework.org/schema/tx"
- 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/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
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- ">
- <import resource="hibernate.xml"/>
- <import resource="aop_schema.xml"/>
- <!--
- <import resource="oa.xml"/>
- <import resource="inludedContext.xml"/>
- --></beans>
- <?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:tx="http://www.springframework.org/schema/tx"
- 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/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
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- ">
- <bean id="b7" class="com.Bean7">
- </bean>
- <bean id="myAspect" class="org.xyz.NotVeryUsefulAspect"></bean>
- <bean id="myAspect2" class="org.xyz.NotVeryUsefulAspect2"></bean>
- <aop:config>
- <aop:pointcut id="businessService"
- expression="execution(public * com.Bean7.*(..))" />
- <aop:aspect id="TestAspect" ref="myAspect">
- <aop:before pointcut-ref="businessService" method="before" />
- <aop:after-returning pointcut-ref="businessService"
- method="after_returning" />
- <aop:after-throwing pointcut-ref="businessService"
- method="after_throwing" />
- <aop:around pointcut-ref="businessService" method="around" />
- </aop:aspect>
- <aop:aspect id="TestAspect2" ref="myAspect2">
- <!--
- <aop:before pointcut-ref="businessService" method="before" />
- <aop:after-returning pointcut-ref="businessService"
- method="after_returning" />
- <aop:after-throwing pointcut-ref="businessService"
- method="after_throwing" />
- -->
- <aop:around pointcut-ref="businessService" method="around" />
- </aop:aspect>
- </aop:config>
- </beans>