国产成人亚洲精品91专区高清,亚洲精品国产精品乱码不卡√,亚洲av鲁丝一区二区三区http://m.tkk7.com/iamlibo/category/33097.htmlzh-cnMon, 23 Dec 2013 13:41:58 GMTMon, 23 Dec 2013 13:41:58 GMT60Spring 3.2 JPA2.0 XML 配置方式http://m.tkk7.com/iamlibo/archive/2013/12/19/407775.htmlLiboLiboThu, 19 Dec 2013 08:17:00 GMThttp://m.tkk7.com/iamlibo/archive/2013/12/19/407775.htmlhttp://m.tkk7.com/iamlibo/comments/407775.htmlhttp://m.tkk7.com/iamlibo/archive/2013/12/19/407775.html#Feedback0http://m.tkk7.com/iamlibo/comments/commentRss/407775.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/407775.html使用maven工程,pom.xml文件如下
<dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.2.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>1.8.5</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.8.Final</version>
        </dependency>

        <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.2.8.Final</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.27</version>
        </dependency>
       <!-- <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>3.0</version>
        </dependency>
-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.2.4.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

dao接口如下:
package cn.test.dao;

/**
 * Created by libo on 13-12-19.
 
*/
public interface IDao {

    void save(Object entity);
}

dao實現類如下:
package cn.test.dao;

import org.springframework.stereotype.Component;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Created by libo on 13-12-19.
 
*/
@Component
public class DaoJpaImpl implements IDao {

    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public void save(Object entity) {
        entityManager.persist(entity);
    }
}

service 接口:
package cn.test.service;

import cn.test.entity.User;

/**
 * Created by libo on 13-12-19.
 
*/
public interface UserService {
    void save(User user);
}

service 實現類:
package cn.test.service;

import cn.test.dao.IDao;
import cn.test.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by libo on 13-12-19.
 
*/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private IDao iDao;

    @Override
    //@Transactional(propagation= Propagation.REQUIRED)
    @Transactional(readOnly = false)
    public void save(User user) {
        iDao.save(user);
    }
}
實體類:
package cn.test.entity;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * Created by libo on 13-12-19.
 
*/
@Entity
@Table(name = "myUser")
public class User implements Serializable{

    @Id
    private String id;

    private String name;

    private int age;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

spring-config.xml 其中
task相關內容可以刪除
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:tx
="http://www.springframework.org/schema/tx"
       xmlns:task
="http://www.springframework.org/schema/task"
       xmlns:context
="http://www.springframework.org/schema/context"
       xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/task
            http://www.springframework.org/schema/task/spring-task-3.1.xsd http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
>
    <context:annotation-config/>
    <context:component-scan base-package="cn.test"/>
    <task:annotation-driven/>

    <bean id="em" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="cn.test.entity"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
            </props>
        </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/spring_jpa"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="em"/>
    </bean>
    <!-- 可以使用@Transactional配置事務 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="persistenceExceptionTranslationPostProcessor"
          class
="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
</beans>

測試類:
package cn.test.service;

import cn.test.entity.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by libo on 13-12-19.
 
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-config.xml")
public class UserServiceImplTest {

    @Autowired
    private UserService userService;

    @Test
    public void testSave() throws Exception {
        User user = new User();
        user.setId("u_id");
        user.setName("u_name");
        user.setAge(23);
        userService.save(user);
    }
}

運行Junit測試就可以了。連接的是MySQL數據庫

end.


Libo 2013-12-19 16:17 發表評論
]]>
Struts2 Action 與Spring bean 作用域http://m.tkk7.com/iamlibo/archive/2012/05/30/379590.htmlLiboLiboWed, 30 May 2012 13:29:00 GMThttp://m.tkk7.com/iamlibo/archive/2012/05/30/379590.htmlhttp://m.tkk7.com/iamlibo/comments/379590.htmlhttp://m.tkk7.com/iamlibo/archive/2012/05/30/379590.html#Feedback0http://m.tkk7.com/iamlibo/comments/commentRss/379590.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/379590.htmlstruts2 action 是沒有scope的,但通過引用spring bean 可以達到有scope功能。

?

?

<action name="xxxAction" class="xxxBean">

<result name="success" >/success.jsp</result>

</action>

?

?xxxBean是在spring中配置的session作用域的bean.

?

@Service(value = "xxxBean")

@Scope(value = "session")

public class XxxAction {

...

}

? ?

?

想把action放到session作用域(因為一些特殊操作傳參等),但所有action都放到session會頭大的!!

?

經過測試發現一個辦法,就是把不用的xxxAction在適當的時候從session當中清除掉,這樣再下次使用(沒有關閉窗口的情況)的時候會再次創建xxxBean

?

現在的難點在于什么時候清除比較合適,一般一個action都是負責一個功能,比如用戶的增、刪、改查等,不會涉及到其他對象,采購單的增、刪、改、查。這樣就可以在通過菜單切換功能(從用戶界面切到采購單界面)的時候將剛剛使用的用戶的actionsession當中清除。

?

基于這樣的思路,使用struts2 的攔截器(Interceptor)來監聽特定的action,在菜單切換的時候從session中清除不用的action

?

?

歡迎提出各種看法!

?

?



Libo 2012-05-30 21:29 發表評論
]]>
JSF2.0 與Spring 3.0 集成http://m.tkk7.com/iamlibo/archive/2010/04/24/319264.htmlLiboLiboSat, 24 Apr 2010 07:03:00 GMThttp://m.tkk7.com/iamlibo/archive/2010/04/24/319264.htmlhttp://m.tkk7.com/iamlibo/comments/319264.htmlhttp://m.tkk7.com/iamlibo/archive/2010/04/24/319264.html#Feedback2http://m.tkk7.com/iamlibo/comments/commentRss/319264.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/319264.html

JSF2.0 與Spring 3.0 集成

同以前的JSF1.2Spring2.5集成類似,只是有一些類名的變化。

web.xml 代碼如下:

<context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>WEB-INF/applicationContext.xml</param-value>
    
</context-param>
    
<listener>
        
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    
</listener>
    
<listener>
        
<listener-class> org.springframework.web.context.ContextLoaderListener
            
</listener-class>
    
</listener>
    
<listener>
        
<listener-class>
            org.springframework.web.context.request.RequestContextListener
</listener-class>
    
</listener>
    
<servlet>
        
<servlet-name>Faces Servlet</servlet-name>
        
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        
<load-on-startup>1</load-on-startup>
    
</servlet>
    
<servlet-mapping>
        
<servlet-name>Faces Servlet</servlet-name>
        
<url-pattern>*.xhtml</url-pattern>
    
</servlet-mapping>
    
<servlet-mapping>
        
<servlet-name>Faces Servlet</servlet-name>
        
<url-pattern>*.jsf</url-pattern>
    
</servlet-mapping>
    
<context-param>
        
<param-name>javax.faces.PROJECT_STAGE</param-name>
        
<param-value>Development</param-value>
    
</context-param>
    
<welcome-file-list>
        
<welcome-file>index.html</welcome-file>
    
</welcome-file-list>


Faces-config.xml中加入:

<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>

JSF1.21.2以前是加入

<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>

Spring 的配置文件就正常配置就可以了。

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"
    xmlns:tx
="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation
="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
>
    
<!--
        <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="WEB-INF/jdbc.properties" /> </bean>
    
-->
    
<!-- hibernate sessionFactory -->
    
<context:annotation-config/>
    
<context:component-scan base-package="cn.xiangyunsoft" />
    
<bean id="sessionFactory"
        class
="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        
<property name="hibernateProperties" value="classpath:hibernate.properties" />
        
<property name="configLocations">
            
<list>
                
<!-- 使用hibernate.cfg.xml配置文件 -->
                
<value>classpath:hibernate.cfg.xml
                
</value>
            
</list>
        
</property>
    
</bean>
    
<!-- 配置事務管理 -->
    
<!-- 事務通知類 -->
    
<!--
        <bean id="profiler"
        class="cn.xiangyunsoft.business.service.SimpleProfiler"> order
        值可以決定通知的先后順序 ,與后面的order的值的大小,決定了是先通知再執行,還是先執行再通知 <property
        name="order" value="2" /> </bean>
    
-->
    
<bean id="transactionManager"
        class
="org.springframework.orm.hibernate3.HibernateTransactionManager">
        
<property name="sessionFactory" ref="sessionFactory" />
    
</bean>
    
<aop:config>
        
<!-- 此處的IService 是表示對所有實現IService接口的類管理事務 -->
        
<aop:advisor
            
pointcut="execution(* cn.xiangyunsoft.*.service..*ServiceImpl.*(..))"
            advice-ref
="txAdvice" />
        
<!--
            加入之后事務不起作用> <aop:aspect id="profilingAspect" ref="profiler">
            <aop:pointcut id="serviceMethodWithReturnValue"
            expression="execution(*
            cn.xiangyunsoft.*.service..*ServiceImpl.*(..))" />
            <aop:after-throwing method="profile"
            pointcut-ref="serviceMethodWithReturnValue" /> </aop:aspect
        
-->
    
</aop:config>
    
<tx:advice id="txAdvice" transaction-manager="transactionManager">
        
<!-- the transactional semantics -->
        
<tx:attributes>
            
<!-- 以get、find、load開頭的方法是只讀事務 -->
            
<tx:method name="*" read-only="true" />
            
<!--<tx:method name="find*" read-only="true" />-->
            
<!--<tx:method name="load*" read-only="true" />-->
            
<!-- 其他方法是默認,事務隔離級別為:保證一個事務修改的數據提交后才能被另外一個事務讀取 -->
            
<tx:method name="save*" isolation="REPEATABLE_READ"
                propagation
="REQUIRED" />
            
<tx:method name="delete*" isolation="REPEATABLE_READ"
                propagation
="REQUIRED" />
                
        
</tx:attributes>
    
</tx:advice>
</beans>


一個注入Spring bean 的 JSF bean 代碼如下:

@ManagedBean(name = ClassItemBean.NAME)
public class ClassItemBean {

    
public static final String NAME = "classItemBean";

    
/*
     *在spring 中配置的service.
     
*/
    @ManagedProperty(name 
= "classItemService", value = "#{classItemService}")
    
private ClassItemService classItemService;

    
public void setClassItemService(ClassItemService classItemService) {
        
this.classItemService = classItemService;
    }

    
public String hello() {
        System.out.println(
"hello." + classItemService);
        Object obj 
= classItemService.get(ClassItem.class"01");
        System.out.println(
"obj = " + obj);
        
return null;
    }
}


這樣集成就完畢了。很簡單,很強大。






Libo 2010-04-24 15:03 發表評論
]]>
spring 動態數據源http://m.tkk7.com/iamlibo/archive/2008/07/20/216231.htmlLiboLiboSun, 20 Jul 2008 12:49:00 GMThttp://m.tkk7.com/iamlibo/archive/2008/07/20/216231.htmlhttp://m.tkk7.com/iamlibo/comments/216231.htmlhttp://m.tkk7.com/iamlibo/archive/2008/07/20/216231.html#Feedback4http://m.tkk7.com/iamlibo/comments/commentRss/216231.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/216231.htmlSpring 可以設置動態數據源,這樣可以對程序來透明的支持切換操作不同的數據庫。

http://oiote.blog.sohu.com/74596942.html 這篇文章寫得非常不錯。測試通過,并準備在項目中使用這個方法。還有幾個問題希望大家給點意見:

首先說一下我的需求:數據庫結構都是一樣,但具體有多少個數據庫不確定(視具體用戶而定),用戶操作那個數據庫要根據登錄的時候進行選擇,或根據用戶的權限而定。這個信息肯定是保存在用戶的登錄信息中(例如:session)

問題1、當有不同的用戶需要操作不同的數據庫時(根據登錄時的選擇或指定),什么時候切換數據庫?是在service層還是dao層?這個信息怎么傳給層中的方法?如果每個方法都加一個參數這樣不太好吧?

問題2、這個頻繁的更換數據庫,會不會有性能影響?因為sessionFactory是一個切換數據庫是不是就是重新初始一次sessionFactory?


附原文如下:

Spring2.0.1以后的版本已經支持配置多數據源,并且可以在運行的時候動態加載不同的數據源。通過繼承 AbstractRoutingDataSource就可以實現多數據源的動態轉換。目前做的項目就是需要訪問12個數據源,每個數據源的表結構都是相同的,所以要求數據源的變動對于編碼人員來說是透明,也就是說同樣SQL語句在不同的環境下操作的數據庫是不一樣的。具體的配置如下:
一、首先需要寫一個靜態的鍵值對照類:


代碼



  1. package cn.com.xinli.ccp.dynamicds;
  2. public class DataSourceMap {
  3. public static final String Admin="Admin";
  4. public static final String Yxh = "Yxh";
  5. }




這個類主要在使用的時候當作獲得數據源的標志使用。
二、建立一個獲得和設置上下文的類:

代碼



  1. package cn.com.xinli.ccp.dynamicds;
  2. public class CustomerContextHolder {
  3. private static final ThreadLocal contextHolder =
  4. new ThreadLocal();
  5. public static void setCustomerType(String customerType) {
  6. contextHolder.set(customerType);
  7. }
  8. public static String getCustomerType() {
  9. return (String) contextHolder.get();
  10. }
  11. public static void clearCustomerType() {
  12. contextHolder.remove();
  13. }
  14. }



這個主要負責設置上下文環境和獲得上下文環境。
三、建立動態數據源類,這個類必須繼承AbstractRoutingDataSource:

代碼



  1. package cn.com.xinli.ccp.dynamicds;
  2. import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
  3. public class DynamicDataSource extends AbstractRoutingDataSource {
  4. protected Object determineCurrentLookupKey() {
  5. // TODO Auto-generated method stub
  6. return CustomerContextHolder.getCustomerType();
  7. }
  8. }



這個類實現了 determineCurrentLookupKey方法,該方法返回一個Object,一般是返回字符串,也可以是枚舉類型。該方法中直接使用了 CustomerContextHolder.getCustomerType()方法獲得上下文環境并直接返回。
四、編寫spring的配置文件配置數據源

代碼



  1. <bean id="parentDataSource"
  2. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  3. <property name="driverClassName">
  4. <value>COM.ibm.db2.jdbc.net.DB2Driver</value>
  5. </property>
  6. <property name="url">
  7. <value>jdbc:db2:127.0.0.1:TEST</value>
  8. </property>
  9. </bean>
  10. <bean id="adminDataSource" parent="parentDataSource">
  11. <property name="username" value="admin"/>
  12. <property name="password" value="master997mb"/>
  13. </bean>
  14. <bean id="yxhDataSource" parent="parentDataSource">
  15. <property name="username" value="yxh"/>
  16. <property name="password" value="yxh"/>
  17. </bean>



在這個配置中可以看到首先有個parentDataSource,這個主要配置一些數據源的公用信息,項目中都是鏈接DB2數據庫;adminDataSource和yxhDataSource是根據不同需要配置的個性化信息,但都必須加parent屬性,值為 parentDataSource。這樣就配置好了2個數據源信息。當然如果鏈接的多數據源是不同類型的兩個數據庫,那么 parentDataSource就可以不要了,直接配置兩個不同的數據源鏈接就可以了。
五、編寫spring配置文件配置多數據源映射關系

代碼



  1. <bean id="dataSource" class="cn.com.xinli.ccp.dynamicds.DynamicDataSource">
  2. <property name="targetDataSources">
  3. <map key-type="java.lang.String">
  4. <entry key="Yxh" value-ref="yxhDataSource"/>
  5. </map>
  6. </property>
  7. <property name="defaultTargetDataSource" ref="adminDataSource"/>
  8. </bean>



在這個配置中第一個property屬性配置目標數據源,<map key-type="java.lang.String">中的key-type必須要和靜態鍵值對照類DataSourceMap中的值的類型相同;<entry key="Yxh" value-ref="yxhDataSource"/>中key的值必須要和靜態鍵值對照類中的值相同,如果有多個值,可以配置多個< entry>標簽。第二個property屬性配置默認的數據源。
六、配置hibernate。
Hibernate的配置和普通的hibernate、spring結合的配置一樣

代碼



  1. <bean id="sessionFactory"
  2. class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  3. <!-- to override, use the "SpringDatasourceConfig" snippet in your project -->
  4. <property name="dataSource">
  5. <ref local="dataSource" />
  6. </property>
  7. <property name="mappingResources">
  8. <list>
  9. <value>
  10. cn/com/xinli/ccp/entity/User.hbm.xml
  11. </value>
  12. <value>
  13. cn/com/xinli/ccp/entity/Test.hbm.xml
  14. </value>
  15. </list>
  16. </property>
  17. <property name="hibernateProperties">
  18. <props>
  19. <prop key="hibernate.dialect">
  20. org.hibernate.dialect.DB2Dialect
  21. </prop>
  22. <prop key="hibernate.show_sql">true</prop>
  23. <prop key="hibernate.use_outer_join">true</prop>
  24. <prop key="hibernate.jdbc.batch_size">50</prop>
  25. <prop key="hibernate.jdbc.fetch_size">5</prop>
  26. <prop key="hibernate.connection.pool_size">2</prop>
  27. <prop key="hibernate.connection.autocommit">false</prop>
  28. <prop key="hibernate.cache.use_query_cache">false</prop>
  29. <prop key="hibernate.max_fetch_depth">1</prop>
  30. <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
  31. </props>
  32. </property>
  33. </bean>
  34. <bean id="mydao" class="cn.com.xinli.ccp.dao.HibernateBaseDao">
  35. <property name="sessionFactory">
  36. <ref local="sessionFactory" />
  37. </property>
  38. </bean>



關于dao的代碼這里就省略了。
七、配置結束,可以使用了。

代碼



  1. public class DaoTest extends TestCase {
  2. public void testSave() throws Exception{
  3. CustomerContextHolder.setCustomerType(DataSourceMap.Admin);//設置數據源
  4. //hibernate創建實體
  5. Test test = new Test();
  6. test.setTest("22222222");
  7. mydao.save(test);//使用dao保存實體
  8. CustomerContextHolder.setCustomerType(DataSourceMap.Yxh);//設置為另一個數據源
  9. mydao.save(test);//使用dao保存實體到另一個庫中
  10. }
  11. }


在項目中對于編碼人員對多數據源的切換可以做成透明的,操作同樣的dao,就可以訪問不同的數據庫了。

Technorati :



Libo 2008-07-20 20:49 發表評論
]]>
從spring配置文件讀取bean的方法http://m.tkk7.com/iamlibo/archive/2008/07/09/213557.htmlLiboLiboWed, 09 Jul 2008 03:13:00 GMThttp://m.tkk7.com/iamlibo/archive/2008/07/09/213557.htmlhttp://m.tkk7.com/iamlibo/comments/213557.htmlhttp://m.tkk7.com/iamlibo/archive/2008/07/09/213557.html#Feedback0http://m.tkk7.com/iamlibo/comments/commentRss/213557.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/213557.html

http://omencathay.itpub.net/post/30163/443031

/**第一種 */
ApplicationContext ac = new FileSystemXmlApplicationContext("serviceContext.xml");
JurisdictionImp jurisdictionImp = (JurisdictionImp)ac.getBean("jurisdictionImp");
/**第二種*/
FileSystemXmlApplicationContext ctx =new FileSystemXmlApplicationContext(CONTEXT_FILE);
JurisdictionImp jurisdictionImp = (JurisdictionImp) ctx.getBean("jurisdictionImp");
/**第三種*/
Resource resource = new ClassPathResource(CONTEXT_FILE);
XmlBeanFactory beanFactory = new XmlBeanFactory( resource);
JurisdictionImp jurisdictionImp=(JurisdictionImp) beanFactory.getBean("jurisdictionImp");
/**第四種*/
ServletContext context=request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
JurisdictionImp jurisdictionImp=(JurisdictionImp) ctx.getBean("jurisdictionImp");
/**第五種*/
/**
* 獲得其它業務類對象
* */
public Object getBean(String name)
{
WebApplicationContext ctx
if (ctx == null)
{
ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(servlet.getServletContext());
}
return ctx.getBean(name);
}



Libo 2008-07-09 11:13 發表評論
]]>
主站蜘蛛池模板: AV在线亚洲男人的天堂| 亚洲AV无码码潮喷在线观看| 黄色网址大全免费| 亚洲人成网77777色在线播放| 99re视频精品全部免费| 亚洲高清毛片一区二区| 中文字幕亚洲综合久久男男| 中文字幕免费在线看线人| 黄色三级三级免费看| 久久久亚洲欧洲日产国码是AV| 巨胸喷奶水视频www网免费| 两个人看www免费视频| 亚洲综合伊人制服丝袜美腿| 亚洲伊人成无码综合网| 青娱乐免费在线视频| 九九热久久免费视频| 亚洲www在线观看| 精品久久久久久亚洲| 成年人网站在线免费观看| 国产一区二区三区免费观看在线| 四虎必出精品亚洲高清| 亚洲国产精品一区二区第一页| 在线观看人成视频免费| 久久国产精品免费观看| 欧洲乱码伦视频免费国产| 亚洲另类视频在线观看| 好看的亚洲黄色经典| 一本久久综合亚洲鲁鲁五月天| 亚洲精品在线免费观看| 国内永久免费crm系统z在线 | 免费国产高清视频| 亚洲w码欧洲s码免费| www免费黄色网| 毛片亚洲AV无码精品国产午夜| 亚洲成人高清在线观看| 亚洲国产成人一区二区三区| 人人狠狠综合久久亚洲高清 | 久久亚洲精品无码| 美国毛片亚洲社区在线观看| 久久久久久久亚洲Av无码| 国产精品亚洲产品一区二区三区 |