28

假设有Service方法类似UserService

package com.hjide.aop;
 
public interface UserService {
	public User getUser(int id) throws Exception;
	public void save(User u) throws Exception;
	public int delete(User u) throws Exception;
}

实现类似如下

package com.hjide.aop;
 
public class UserServiceImpl implements UserService {
 
	public int delete(User u)  throws Exception{
		System.out.println("delete");
		return 0;
	}
 
	public User getUser(int id) throws Exception {
		User u = new User();
		u.setId(1);
		u.setName("new user");
		u.setType(2);
		System.out.println("getUser");
		return u;
	}
 
	public void save(User u) throws Exception {
		System.out.println("save");
	}
 
}

更多详细内容 »

Tags: ,

作者:Jock

18

以下是我在其它论坛上发表的问题:

QUOTE:
我采用AbstractDependencyInjectionSpringContextTests进行测试,通过以下代码进行加载.
       protected String[] getConfigLocations() {                return new String[] { "classpath:springapplicationcontext.xml" };        }
以下是我原来的配置文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
       <bean id="dataSource"
               class="org.apache.commons.dbcp.BasicDataSource">
               <property name="driverClassName">
                       <value>oracle.jdbc.driver.OracleDriver</value>
字串1

               </property>
               <property name="url">
                       <value>jdbc:oracle:thin:@localhost:1521:oracle9</value>
               </property>
               <property name="username">
                       <value>gap</value>
               </property>
               <property name="password">
                       <value>gap</value>
               </property>
       </bean> 字串3
       <bean id="sessionFactory"
               class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
               <property name="dataSource" ref="dataSource" />
               <property name="configLocation">
                       <value>classpath:hibernate.cfg.xml</value>
               </property>
       </bean>
       <bean id="txManager"
               class="org.springframework.orm.hibernate3.HibernateTransactionManager">
               <property name="sessionFactory" ref="sessionFactory" /> 字串9
       </bean>
       <bean id="gapdictionaryDao" class="org.gap.dao.GapdictionaryDao">
               <property name="sessionFactory">
                       <ref bean="sessionFactory" />
               </property>
       </bean>
       <bean id="gap" class="org.gap.service.GapImpl">
               <property name="gapdictionaryDao" ref="gapdictionaryDao" />
       </bean>
</beans>

以下是我新的配置文件: 更多详细内容 »

Tags: ,

作者:Jock

29

一、struts2。

跟webwork配置基本一致,主要是struts2.properties和struts.xml 2个配置文件,我的struts2.properties如下配置:

struts2.properties 更多详细内容 »

Tags: , , ,

作者:Jock

25

首先来2个最简单的bean

package example;
 
/**
* @author jockhuang
*
*/
public class TestA {
 
public void sayHello(){
    System.out.println("TestA");
}
 
}
package example;
 
public class TestB {
    public void sayHi(){
        System.out.println("TestB");
    }
}

2个很简单的bean,applicationContext.xml中的配置如下:

< ?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-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="TestA" class="example.TestA"></bean>
<bean id="TestB" class="example.TestB"></bean>
</beans>

来个测试运行这2个bean

package example;
 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
public final class TestAOP {
 
  public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    TestA a = (TestA) ctx.getBean("TestA");
    a.sayHello();
    TestB b = (TestB) ctx.getBean("TestB");
    b.sayHi();
  }
 
}

更多详细内容 »

Tags: ,

作者:Jock

17

Spring_2.0_Reference_zh_CN.chm


Spring 2.0 中文参考手册 chm下载

Tags: , ,

作者:Jock

Switch to our mobile site