国产亚洲精aa在线看,亚洲av无码专区在线电影,亚洲色无码专区一区http://www.tkk7.com/lzj520/category/23581.htmlzh-cnWed, 19 Mar 2008 08:51:45 GMTWed, 19 Mar 2008 08:51:45 GMT60spring中連接池的配置http://www.tkk7.com/lzj520/archive/2008/03/19/187211.htmllzj520lzj520Wed, 19 Mar 2008 04:09:00 GMThttp://www.tkk7.com/lzj520/archive/2008/03/19/187211.htmlhttp://www.tkk7.com/lzj520/comments/187211.htmlhttp://www.tkk7.com/lzj520/archive/2008/03/19/187211.html#Feedback0http://www.tkk7.com/lzj520/comments/commentRss/187211.htmlhttp://www.tkk7.com/lzj520/services/trackbacks/187211.html在默認通過myeclipse生成的配置里,spring使用的是apache的dbcp連接池

<bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName"
   value="com.mysql.jdbc.Driver">
  </property>
  <property name="url"
   value="jdbc:mysql://localhost:3306/mysql">
  </property>
  <property name="username" value="root"></property>
  <property name="password" value="root"></property>
 </bean>

如果改為C3P0則為:

<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:jdbc.properties</value>
        </property>
    </bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="autoCommitOnClose" value="true"/>
        <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
        <property name="initialPoolSize" value="${cpool.minPoolSize}"/>
        <property name="minPoolSize" value="${cpool.minPoolSize}"/>
        <property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
        <property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
        <property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
        <property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
    </bean>
jdbc.properties:

# Database URL
jdbc.url=jdbc:mysql://192.168.0.25"3306/db

# Database login information
jdbc.username=root
jdbc.password=

# Time to wait for an open connection before timing out
# (in milliseconds)
cpool.checkoutTimeout=5000

# Connection pool size
cpool.minPoolSize=5
cpool.maxPoolSize=40

# How long to keep unused connections around(in seconds)
# Note: MySQL times out idle connections after 8 hours(28,800 seconds)
# so ensure this value is below MySQL idle timeout
cpool.maxIdleTime=25200

# How long to hang on to excess unused connections after traffic spike
# (in seconds)
cpool.maxIdleTimeExcessConnections=1800

# Acquiring new connections is slow, so eagerly retrieve extra connections
# when current pool size is reached
cpool.acquireIncrement=5

或者將上面的3部分寫成一個:
<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
      <property name="driverClass">
        <value>${jdbc.driverClassName}</value>
      </property>
      <property name="jdbcUrl">
        <value>${jdbc.url}</value>
      </property>
      <property name="user">
       <value>${jdbc.username}</value>
      </property>
      <property name="password">
       <value>${jdbc.password}</value>
      </property>
      <property name="initialPoolSize"><value>10</value></property>
      <property name="minPoolSize"><value>5</value></property>
      <property name="maxPoolSize"><value>30</value></property>
      <property name="acquireIncrement"><value>5</value></property>
      <property name="maxIdleTime"><value>10</value></property>
      <property name="maxStatements"><value>0</value></property>
    </bean>

如果使用的是受管理的J2EE服務器,則在spring中配置為JNDI連接:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jndi/xxx</value>
</property>
</bean>

如果在應用里有獨自使用hibernate,則在spring中配置hibernate連接池,使用C3P0如下:
<bean   id="DataSource"  
  class="org.apache.commons.dbcp.BasicDataSource">  
  <property   name="driverClassName">  
  <value>oracle.jdbc.driver.OracleDriver</value>  
  </property>  
  <property   name="url">  
  <value>jdbc:oracle:thin:@172.16.20.241:1521:dbsvr</value>  
  </property>  
  <property   name="username">  
  <value>hl3000</value>  
  </property>  
  <property   name="password">  
  <value>hldw3101</value>  
  </property>  
  </bean>  
  <bean   id="SessionFactory"  
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  <property   name="dataSource">  
  <ref   bean="DataSource"   />  
  </property>  
  <property   name="hibernateProperties">  
  <props>  
  <prop   key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>  
  <prop   key="hibernate.show_sql">true</prop>  
   
  <!--   C3P0連接池配置   -->  
  <prop   key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>  
  <prop   key="hibernate.c3p0.max_size">20</prop>  
  <prop   key="hibernate.c3p0.min_size">5</prop>  
  <prop   key="hibernate.c3p0.timeout">120</prop>  
  <prop   key="hibernate.c3p0.max_statements">100</prop>  
  <prop   key="hibernate.c3p0.idle_test_period">120</prop>  
  <prop   key="hibernate.c3p0.acquire_increment">2</prop>  
  <prop   key="myeclipse.connection.profile">hl3000</prop>  
  </props>  
  </property>  
  <property   name="mappingResources">  
  <list>  
  <value>com/hl3000/DBLogic/POJO/PermUserAccount.hbm.xml</value>  
  </list>  
  </property>  
  </bean> 

spring中配置獨立使用hibernate時使用jndi的配置:

hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.datasource=java:comp/env/jdbc/SAMPLEDB
hibernate.show_sql=true

如果是使用不受管理的Servlet容器如Tomcat,也可以使用jndi的方式配置,需要在tomcat中配置數(shù)據(jù)源,在server.xml中增改大致如下:

     <Resource name="jdbc/testDb" auth="Container"
                    type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/testDB">\\數(shù)據(jù)源的名稱
            <parameter><name>username</name><value>root</value></parameter>數(shù)據(jù)庫的名稱
            <parameter><name>password</name><value>password</value></parameter>數(shù)據(jù)庫密碼
            <parameter><name>driverClassName</name>
              <value>org.gjt.mm.mysql.Driver</value></parameter>\\要加載的驅(qū)動
            <parameter><name>url</name>
              <value>jdbc:mysql://172.20.0.73/rk?</value></parameter>\\要連接的URL
          </ResourceParams>



lzj520 2008-03-19 12:09 發(fā)表評論
]]>
ssh上傳并顯示圖片http://www.tkk7.com/lzj520/archive/2008/01/17/176020.htmllzj520lzj520Thu, 17 Jan 2008 09:44:00 GMThttp://www.tkk7.com/lzj520/archive/2008/01/17/176020.htmlhttp://www.tkk7.com/lzj520/comments/176020.htmlhttp://www.tkk7.com/lzj520/archive/2008/01/17/176020.html#Feedback0http://www.tkk7.com/lzj520/comments/commentRss/176020.htmlhttp://www.tkk7.com/lzj520/services/trackbacks/176020.html
struts部分:

 <form-bean name="upfileForm" type="org.apache.struts.validator.DynaValidatorForm">
      <form-property name="filename" type="java.lang.String" />
      <form-property name="filedata" type="org.apache.struts.upload.FormFile" />
    </form-bean>

    <action
      attribute="upfileForm"
      input="/upload/uploadfile.jsp"
      name="upfileForm"
      path="/upfile"
      scope="request"
      validate="true"
      type="com.yourcompany.struts.action.UpfileAction">
      <forward name="ok" path="/upload/ok.jsp" />
    </action>

    <action path="/displayimg" type="com.yourcompany.struts.action.DisplayimgAction">
      <forward name="ok" path="/upload/displayimg.jsp" />
    </action>

 

public class UpfileAction extends Action {
 /*
  * Generated Methods
  */

 /**
  * Method execute
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  DynaActionForm upfileForm = (DynaActionForm) form;// TODO Auto-generated method stub  
   Image image = new Image();

   String strimgname = upfileForm.getString("filename");
   image.setImgname(strimgname);
   imageDAO.save(image); 
  FormFile filedata = (FormFile)upfileForm.get("filedata");
   ServletContext servletContext = this.getServlet().getServletContext();
   String filePath = servletContext.getRealPath("/");
   try {
    InputStream stream = filedata.getInputStream();
    OutputStream bos = new FileOutputStream(filePath + "/image/" + filedata.getFileName());
     int bytesRead = 0;
             byte[] buffer = new byte[8192];
             while ( (bytesRead = stream.read(buffer, 0, 8192)) != -1) {
             bos.write(buffer, 0, bytesRead);
             }
             bos.close();
             stream.close();
   }catch (FileNotFoundException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
         return mapping.findForward("ok");
 }
 
 private ImageDAO imageDAO;
 public void setImageDAO(ImageDAO dao){
  this.imageDAO = dao;  
 }
 
}


 

public class DisplayimgAction extends Action {
 /*
  * Generated Methods
  */

 /**
  * Method execute
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  // TODO Auto-generated method stub
  List results = imageDAO.findAll();
  if(results!=null){
   HttpSession session=request.getSession();
            session.setAttribute("results",results);
            return mapping.findForward("ok");
  }return mapping.findForward("fail");
 }
 
 private ImageDAO imageDAO;
 public void setImageDAO(ImageDAO dao){
  this.imageDAO = dao;  
 }
 
}


ImageDAO.java

 public void save(Image transientInstance) {
     Session session =this.getSession();
     Transaction tx = null;
     tx = session.beginTransaction();
     session.save(transientInstance);
     tx.commit();
     session.evict(transientInstance);
 }

 public List findAll() {
  Session session =this.getSession();
  Query query = session.createQuery("from Image");
  return query.list();
 }

displayimg.jsp

<logic:iterate id="element" name="results">
    <tr>
   <td width="100"><bean:write name="element" property="id"/> </td>
   <td width="100"><img  src="image/<bean:write  name='element' property='imgname'/>"/></td>
   </tr>
</logic:iterate>

uploadfile.jsp

<html:form action="/upfile" enctype = "multipart/form-data">
   filename : <html:text  property="filename"/><html:errors property="filename"/><br/>
   filedata : <html:file property="filedata"/><html:errors property="filedata"/><br/>
   <html:submit/><html:cancel/>
  </html:form>

<!-- u-f8 filter -->
  <filter>
  <filter-name>encodingFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>UTF-8</param-value>
  </init-param>
 </filter>

 <filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>*.do</url-pattern>
 </filter-mapping>

 <filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
 </filter-mapping>



lzj520 2008-01-17 17:44 發(fā)表評論
]]>
自己寫了一個ssh分頁http://www.tkk7.com/lzj520/archive/2008/01/10/174373.htmllzj520lzj520Thu, 10 Jan 2008 10:55:00 GMThttp://www.tkk7.com/lzj520/archive/2008/01/10/174373.htmlhttp://www.tkk7.com/lzj520/comments/174373.htmlhttp://www.tkk7.com/lzj520/archive/2008/01/10/174373.html#Feedback2http://www.tkk7.com/lzj520/comments/commentRss/174373.htmlhttp://www.tkk7.com/lzj520/services/trackbacks/174373.html
首先,先創(chuàng)建一個顯示每一頁(有若干條數(shù)據(jù))的方法(如下面的hfindAll方法),決定好每一頁接收一個頁碼參數(shù),然后顯示該頁碼里的數(shù)據(jù)。比如有100條數(shù)據(jù),那么分10頁,那第幾頁顯示第幾條至第幾條數(shù)據(jù)。然后再創(chuàng)建一個方法是用于在view層顯示頁數(shù)(如下面的amountPage方法),最后是在view層上為每一頁數(shù)的數(shù)字加上超鏈接。

以下是主要代碼:
public class LoginDAO extends HibernateDaoSupport {
private int PageSize =5;
/*設置每頁的數(shù)據(jù)條數(shù)*/

 public Integer amountPage(){
     Session session =this.getSession();
  Query query = session.createQuery("from Login");
  query.setCacheable(true);
  int a = query.list().size()%PageSize;
/*總記錄數(shù)/每頁數(shù)據(jù)數(shù),判斷是否能整除*/
  Integer amount;
  if(a!=0){
   amount = query.list().size()/PageSize+1;
/*如果整除有余數(shù),則頁數(shù)加1*/
  }else{
   amount = query.list().size()/PageSize;
/*如果整除沒余數(shù),則直接總記錄數(shù)/每頁數(shù)據(jù)數(shù)*/
  }
  return amount;
 }

 public List hfindAll(String pagenum) {
     Session session =this.getSession();
  Query query = session.createQuery("from Login");
  if (pagenum == null){
/*如果pagenum是空,則數(shù)據(jù)從第一條開始*/
  query.setFirstResult(0);
/*設置查詢開始的第幾條數(shù)據(jù),這里是從第1條開始*/
  query.setMaxResults(PageSize);
/*設置查詢數(shù)據(jù)條數(shù),這里是5條*/
  query.setCacheable(true);
/*設置一級緩存*/
  }else{
   Integer p = (Integer.valueOf(pagenum)-1) * PageSize;
   query.setFirstResult(p);
   query.setMaxResults(PageSize);
   query.setCacheable(true);
  }
  return query.list();
 }
}

然后需要解決的是一些數(shù)據(jù)傳遞,類型轉(zhuǎn)換和在view層顯示的問題,主要代碼如下:

在ACTION里:
String strpagenum = request.getParameter("pagenum");
  List results= loginManage.hfind(strpagenum);
  Integer amountPage = loginManage.amountPage();
    if(results!=null){
             HttpSession session=request.getSession();
             session.setAttribute("results",results);
             session.setAttribute("amountPage",amountPage);
             return mapping.findForward("ok");
         }
    return mapping.findForward("fail");

在view視圖里:
顯示每頁數(shù)據(jù)的代碼:

 <logic:iterate id="element" name="results">    <tr>
   <td width="100"><input type="checkbox" name="select" value="<bean:write name="element" property="id"/>"><bean:write name="element" property="id"/></td>
   <td width="100"><bean:write name="element" property="name"/> </td>
   <td width="100"><bean:write name="element" property="password"/></td>
   </tr></logic:iterate>

顯示頁碼的代碼:
<%
   int i;
  int a=Integer.parseInt(session.getAttribute("amountPage").toString());
   for (i=1;i<=a;i++){
   out.println("<tr>");  
          out.println("<td><a href='display.do?pagenum="+ i +"'>"+ i +"</a></td>");    
          out.println("</tr>");    
   }
    %>




lzj520 2008-01-10 18:55 發(fā)表評論
]]>
spring+hibernate里session的管理http://www.tkk7.com/lzj520/archive/2008/01/10/174392.htmllzj520lzj520Thu, 10 Jan 2008 10:41:00 GMThttp://www.tkk7.com/lzj520/archive/2008/01/10/174392.htmlhttp://www.tkk7.com/lzj520/comments/174392.htmlhttp://www.tkk7.com/lzj520/archive/2008/01/10/174392.html#Feedback0http://www.tkk7.com/lzj520/comments/commentRss/174392.htmlhttp://www.tkk7.com/lzj520/services/trackbacks/174392.html 或者是[org.hibernate.jdbc.ConnectionManager] - <finalizing with closed connection>
那是因為有可能是你自己手動創(chuàng)建了session,比如:

private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
然后調(diào)用:

Session session = sessionFactory.openSession();
Query query = session.createQuery("from Login");

類似這樣的單獨使用hibernate時的用法,是需要手工去關閉session的。沒有關閉的話就會收到那樣的警告。

所以最好是使用spring管理的session,和OpenSessionInViewFilter,比如:
Session session =this.getSession();
然后在web.xml里加入
  <filter>
  <filter-name>OpenSessionInViewFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

其中在spring里注冊的sessionfactory必須是id="sessionFactory",如果是id="SessionFactory"或者其他,會提示sessionFactory沒有注冊的錯誤,因為OpenSessionInViewFilter里注冊的名必須為sessionFactory。



lzj520 2008-01-10 18:41 發(fā)表評論
]]>
070827 hibernate關聯(lián)、聯(lián)級操作、對象生命周期、檢索策略http://www.tkk7.com/lzj520/archive/2007/08/27/139776.htmllzj520lzj520Mon, 27 Aug 2007 02:15:00 GMThttp://www.tkk7.com/lzj520/archive/2007/08/27/139776.htmlhttp://www.tkk7.com/lzj520/comments/139776.htmlhttp://www.tkk7.com/lzj520/archive/2007/08/27/139776.html#Feedback0http://www.tkk7.com/lzj520/comments/commentRss/139776.htmlhttp://www.tkk7.com/lzj520/services/trackbacks/139776.html在mysql里建立2個表
CREATE TABLE `customers` (
  `id` int(11) NOT NULL auto_increment,
  `name` char(20) character set latin1 default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `orders` (
  `id` int(11) NOT NULL auto_increment,
  `customer_id` int(50) NOT NULL default '0',
  `order_number` int(50) default NULL,
  PRIMARY KEY  (`id`),
  KEY `fk_customer_id` (`customer_id`),
  CONSTRAINT `fk_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

然后自動生成持久化類,在customers.hbm.xml一方設置與orders的外鍵customer_id的一對多關聯(lián),其中聯(lián)級操作為save-update,inverse="true"為表示hibernate不由customers對象的狀態(tài)變化來更新數(shù)據(jù)庫,僅按照Orders對象狀態(tài)變化來更新數(shù)據(jù)庫。由此來優(yōu)化hibernate的性能。
 <set name="orderses" inverse="true" cascade="save-update">
            <key>
                <column name="customer_id" unique="true" />
            </key>
            <one-to-many class="com.yourcompany.model.Orders" />
        </set>

在orders.hbm.xml設置多對一關聯(lián),其中業(yè)務邏輯決定了order是由customer來下決定的,所以必須not-null="true" ,聯(lián)級操作根據(jù)實際情況而定,本例子的邏輯關系里面,應該不需要在many-to-one一方設置save-update聯(lián)級操作,因為增加orders并不需要增加customer。在目前的情況里如果設置了save-update,增加orders記錄的時候hibernate就會把原來已存在的customers記錄設置為null。這是不對的。
        <many-to-one name="customers" class="com.yourcompany.model.Customers" fetch="select" >
            <column name="customer_id" not-null="true" unique="true" />
        </many-to-one>

在AddCustomerAction里保存一個customers,之后可以看到當保存一個customers的同時,orders也同時保存了該customers的id。
  String strname = addCustomerForm.getString("name");
  Customers customers = new  Customers();
  customers.setName(strname);
  Orders orders=new Orders();
  orders.setCustomers(customers);
  customers.getOrderses().add(orders);
  customersDAO.save(customers);

其中
  orders.setCustomers(customers);
  customers.getOrderses().add(orders);
在建立兩個對象的雙向關聯(lián)時,應該同時修改關聯(lián)兩端的對象的相應屬性,這樣可提高業(yè)務邏輯的獨立性。
比如:解除雙向關聯(lián)時:
  customers.getOrderses().remove(orders);
  orders.setCustomers(null);

在AddOrdersAction里,由表單傳入customers的ID值和新增加的order_number值。ordersDAO.attachDirty(orders);為Myeclipse里生成的DAO,其調(diào)用的是HibernateTemplate的getHibernateTemplate().saveOrUpdate(instance);方法。
  Integer strcustomers= Integer.valueOf(addOrdersForm.getString("customers"));
  Integer strorder_number= Integer.valueOf(addOrdersForm.getString("order_number"));
  Orders orders = new  Orders(); 
  Customers customers = new  Customers();
  customers.setId(strcustomers);
  orders.setCustomers(customers);
  orders.setOrderNumber(strorder_number);
  ordersDAO.attachDirty(orders);

在這里的持久化對象的生命周期里,當Customers customers = new  Customers();時,Customers還屬于臨時狀態(tài),而到了sessionv.save(customers);的時候Customers由臨時狀態(tài)轉(zhuǎn)變?yōu)槌志没癄顟B(tài)。臨時狀態(tài)時不處于Session緩存中,轉(zhuǎn)化為持久化狀態(tài)后Customers就加入到了Session緩存中,在此Customers customers 2=(Customers)session.load(Customer.class,id);、Customers customers 3=(Customers)session.load(Customer.class,id);、均是在持久化狀態(tài)。而直到session.close();就表明Customers退出了Session緩存,由持久化狀態(tài)轉(zhuǎn)變?yōu)橛坞x狀態(tài)。System.out.println(customers 3.getname());也是處于游離狀態(tài)。到最后c2=null;c3=null;Customers生命周期結束。

Session有三種檢索方法:load()、get()、find(),檢索策略有類級別的:立即檢索、延遲檢索,關聯(lián)級別的立即檢索、延遲檢索、迫切左外連接檢索。在類級別中應該有線考慮使用立即檢索。不管hbm文件里lazy屬性是true還是false,Session的get()、find()方法總是使用立即檢索策略。

在一對多關聯(lián)級別中,對于<set>元素不能隨意使用立即檢索策略,盡量使用延遲檢索策略。應用程序如果新聞訪問游離狀態(tài)的代理類實例,必須保證它在持久化狀態(tài)時已經(jīng)被初始化,不然會拋出異常

對于多對一或一對一關聯(lián),應該優(yōu)先考慮使用外連接檢索策略,因為它比立即檢索策略使用的select語句數(shù)目少。在默認情況下<many-to-one>元素的outer-join屬性為auto,<class>元素的lazy屬性為false,因此默認使用迫切外連接檢索策略。迫切外連接檢索策略受數(shù)據(jù)庫表的大小和連接影響,如果select語句中的外連接表的數(shù)目太多,會影響檢索性能,可以通過Hibernate配置文件中的hibernate.max_fetch_depth來達到優(yōu)化。hibernate.max_fetch_depth取決數(shù)據(jù)庫連接性能及表大小。



lzj520 2007-08-27 10:15 發(fā)表評論
]]>
070621 SSH一些出錯小結(不斷更新)http://www.tkk7.com/lzj520/archive/2007/06/21/125513.htmllzj520lzj520Thu, 21 Jun 2007 04:01:00 GMThttp://www.tkk7.com/lzj520/archive/2007/06/21/125513.htmlhttp://www.tkk7.com/lzj520/comments/125513.htmlhttp://www.tkk7.com/lzj520/archive/2007/06/21/125513.html#Feedback0http://www.tkk7.com/lzj520/comments/commentRss/125513.htmlhttp://www.tkk7.com/lzj520/services/trackbacks/125513.htmlSpring Hibernate在AOP方面的配置沖突
Spring2.0 Hibernate3.1.x/Hibernate3.2

在使用Spring的AOP編程時,會用到這幾個lib:
asm-2.2.2.jar
asm-commons-2.2.2.jar
asm-util-2.2.2.jar

Hibernate如果使用lib:
asm.jar
asm-attrs.jar

其中asm-2.2.2.jar與asm.jar存在類上的沖突?。?!
使用其中之一或兩者都使用,可能會出現(xiàn)如下錯誤:
java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit。。。。。。

解決辦法是:
1).去掉類路徑上的關于Hibernate的3個lib
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
2).加入Spring中的以下4個lib
asm-2.2.2.jar
asm-commons-2.2.2.jar
asm-util-2.2.2.jar
cglib-nodep-2.1_3.jar

如果再不行,都試試刪刪看。


java.lang.SecurityException: class "javax.xml.bind.JAXBContext"'s signer information does not match signer information of other classes in the same package
這個錯誤是因為載入的包里面有兩個相同路徑的類,就是在一個包里面有兩個同名的類
有可能是將相同的包載入兩次或者把包解開后,先將jar文件載入了,后又將解開的類載入了


Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
試試自己去下一個spring的包,把包里的spring.jar加到項目里去。eclipse生成的時候可能會有些包沒有放進去。


Error creating bean with name 'datasource' defined in file
Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
試試將commons-dbcp.jar,commons-pool.jar和commons- collections.jar加入CLASSPATH中


hibernate 3.1 中的hibernateTemplate ,class應該為org.springframework.orm.hibernate3.HibernateTemplate,而非org.springframework.orm.hibernate.HibernateTemplate,因為某些原因我現(xiàn)在還用3.1,早前在玩springside的時候感覺hibernate 3.2 的Hibernate Annotations方便多了。

找不到action或報錯的另一少有原因,一些版本hibernate版本會有些沖突方面的問題,可換一版本的hibernate試試,個人感覺hibernate的版本對應用會比較敏感


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in resource [/WEB-INF/dataAccessContext-hibernate.xml] of ServletContext: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
java.lang.NoClassDefFoundError: javax/transaction/TransactionManager


原因:缺少jta.jar 或者是找不到hbm.xml文件導致sessionfactory出錯,檢查hbm文件路徑是否正確,文件是否存在
<property name="mappingResources">
  <list>
  <value>com/yourcompany/model/Login.hbm.xml
  </value>
  </list>
  </property>


2007-06-26 18:38:13,671 ERROR [com.yourcompany.model.dao.LoginDAO] - <save failed>
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not insert: [com.yourcompany.model.Login]; bad SQL grammar [insert into mysql__login (name, password) values (?, ?)]; nested exception is java.sql.SQLException: Table 'mysql.mysql__login' doesn't exist
java.sql.SQLException: Table 'mysql.mysql__login' doesn't exist

把hbm文件里面的catalog="'mysql"去掉即可!
另注意的一點是eclipse生成的DAO文件應該是:
    public void save(Login transientInstance) {
        log.debug("saving Login instance");
        try {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
而不是原來的    public void save(LoginDAO transientInstance)

只要在applicationContext.xml中加上
<property name="mappingResources">
<list>
<value>com/yourcompany/hibernate/Users.hbm.xml</value>
</list>
</property>
加這段代碼就會找不到action
換一個版本的hibernate應該就ok


Invalid path /addcustomer was requested
輸入的路徑不正確,檢查spring中注冊的action的路徑和輸入的路徑是否一致,留意大小寫是否一致



lzj520 2007-06-21 12:01 發(fā)表評論
]]>
主站蜘蛛池模板: 亚洲最大成人网色香蕉| 久久精品亚洲视频| 亚洲AV无码专区在线厂| 最近最新中文字幕完整版免费高清| 亚洲AV日韩AV天堂久久| 久久爰www免费人成| 亚洲2022国产成人精品无码区| 毛片在线播放免费观看| 亚洲成熟xxxxx电影| 最近在线2018视频免费观看| 亚洲AV日韩AV天堂久久| 91福利视频免费| 91嫩草亚洲精品| 成人毛片免费在线观看| 精品国产亚洲AV麻豆| 国产亚洲福利一区二区免费看| 看免费毛片天天看| 亚洲精品成人在线| 久久国产精品免费观看| 亚洲综合男人的天堂色婷婷| 免费人成网站在线观看10分钟| 亚洲精品中文字幕无码A片老| 国产无遮挡吃胸膜奶免费看| 亚洲免费无码在线| 久久亚洲私人国产精品vA | 久久av无码专区亚洲av桃花岛| 中国xxxxx高清免费看视频| 亚洲国产区男人本色在线观看| 免费观看国产精品| 97在线免费观看视频| 亚洲乱码无限2021芒果| 国产最新凸凹视频免费| 鲁丝片一区二区三区免费 | 亚洲a∨无码一区二区| 中文字幕亚洲电影| 国产精品免费观看| 国产综合激情在线亚洲第一页 | 亚洲精品线路一在线观看| 国产免费一区二区三区不卡 | 亚洲一区二区三区亚瑟| 亚洲精品456播放|