weixin_42308597
2009-04-28 15:35
浏览 246
已采纳

struts2 spring hibernate3 连mysql问题

我用struts2+spring+hibernate3连数据库mysql,只要访问8次action,ie就停顿了,就一直在加载,控制台也没反应。只能重启服务器tomcat,重启之后也只能访问8次。mysql中最大连接数配置max_connections=1024
spring-common.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost:3306/facebs?useunicode=true&amp;characterEncoding=utf-8</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value>344</value>
        </property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
    >
        <property name="mappingResources">
            <list>
                <value>com/idbao/common/hibernate/AccountState.hbm.xml</value>
<!--........省略一部分<value>-->           </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                </prop>
                <prop key="hibernate.show_sql">
                    true
                </prop>
                <prop key="hibernate.c3p0.min_size">5</prop> 
                <prop key="hibernate.c3p0.max_size">20</prop> 
                <prop key="hibernate.c3p0.timeout">1800</prop> 
                <prop key="hibernate.c3p0.max_statements">50</prop> 
            </props>  
        </property>
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
        
                

        
    </bean>
    <bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>
    </bean>
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>
    </bean>
    <bean id="smsUtil" class="com.idbao.common.util.SmsUtil">
    </bean>
</beans>

 spring-service.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
    <bean id="memberInfoServiceTarget" 
        class="com.idbao.member.service.impl.MemberInfoServiceImpl">
        <property name="memberInfoDao">
            <ref bean="memberInfoDao"/>
        </property>
        <property name="smsUtil">
            <ref bean="smsUtil"/>
        </property>
    </bean>
    
    <bean id="memberInfoService"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
        lazy-init="true">
        <property name="transactionManager">
            <ref bean="transactionManager" />
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="*">PROPAGATION_REQUIRED, -MemberInfoException</prop>
            </props>
        </property>
        <property name="target">
            <ref bean="memberInfoServiceTarget"/>
        </property>
    </bean>
<!--.....省略一部分bean-->
</beans>

  
daoImp.java

public class daoImpl implements dao {
    private HibernateTemplate hibernateTemplate;
    public void setHibernateTemplate(HibernateTemplate hibernateTemplate){
        this.hibernateTemplate=hibernateTemplate;
    }
    public CateringBaseParameter findCatering(Integer id) throws DataAccessException {
        List list=hibernateTemplate.find("from CateringBaseParameter where id=?",id);
        if(list.size()!=0)
            return (CateringBaseParameter) list.get(0);
        return null;
    }
}

 

请指教有什么错误,不胜感激!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • wanghaolovezlq 2009-04-28 16:33
    已采纳

    八成是你的数据库连接没有及时的释放,访问8次action,就取了8个连接,就挂在那边了,

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • weixin_42297497 2009-04-28 15:52

    你debug一下代码,看看在哪步执行的很慢,然后相应的去优化

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题