当前位置:编程学习 > JAVA >>

新手SSH部署出异常.....

按书本的例题演练,是一个简单的运用SSH来实现注册的功能。。先汗个 不用SSH三下五除二的事,  现在变得那么麻烦!



2011-11-17 03:15:33,234 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
2011-11-17 03:15:33,500 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@796e1c: display name [Root WebApplicationContext]; startup date [Thu Nov 17 03:15:33 CST 2011]; root of context hierarchy
2011-11-17 03:15:33,937 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from file [C:\Program Files\apache-tomcat-6.0.26\webapps\ssh\WEB-INF\classes\applicationContext.xml]
2011-11-17 03:15:34,156 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@796e1c]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1bd9d76
2011-11-17 03:15:35,093 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1bd9d76: defining beans [dataSource,sessionFactory,transactionManager,transactionInterceptor,org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator#0,baseDao,userManager,RegAction]; root of factory hierarchy
2011-11-17 03:15:35,187 INFO [com.mchange.v2.log.MLog] - MLog clients using log4j logging.
2011-11-17 03:15:35,531 INFO [com.mchange.v2.c3p0.C3P0Registry] - Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
2011-11-17 03:15:37,234 INFO [org.hibernate.annotations.common.Version] - HCANN000001: Hibernate Commons Annotations {4.0.0.CR2}
2011-11-17 03:15:37,281 INFO [org.hibernate.Version] - HHH000412: Hibernate Core {4.0.0.CR5}
2011-11-17 03:15:37,296 INFO [org.hibernate.cfg.Environment] - HHH000206: hibernate.properties not found
2011-11-17 03:15:37,312 INFO [org.hibernate.cfg.Environment] - HHH000021: Bytecode provider name : javassist
2011-11-17 03:15:37,953 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2011-11-17 03:15:38,656 INFO [org.springframework.orm.hibernate3.LocalSessionFactoryBean] - Building new Hibernate SessionFactory
2011-11-17 03:15:39,218 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] - HHH000130: Instantiating explicit connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2011-11-17 03:15:39,218 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1bd9d76: defining beans [dataSource,sessionFactory,transactionManager,transactionInterceptor,org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator#0,baseDao,userManager,RegAction]; root of factory hierarchy
2011-11-17 03:15:39,234 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed


上面的只是log部分,方便大家差错,下面才是报出的异常
-----------------------------------------------------------------------------------------




org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [C:\Program Files\apache-tomcat-6.0.26\webapps\ssh\WEB-INF\classes\applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)


--------------------编程问答-------------------- ———————————————————————————————————————————————————————再是有关applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
 "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<!-- 配置数据源 -->  
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:jtds:sqlserver://localhost:1433/ssh"></property>

<property name="user" value="sa"></property>
<property name="password" value="accp"></property>
<property name="maxPoolSize" value="80"></property>
<property name="minPoolSize" value="1"></property>
<property name="initialPoolSize" value="1"></property>
<property name="maxIdleTime" value="20"></property>
</bean>



<!-- 配置Hibernate的SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" >
<ref local="dataSource"/>
</property>

<property name="mappingResources">
<list>
<value>User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="show_sql">true</prop>
     <prop key="hibernate.deilect">org.hibernate.dialect.SQLServerDialect</prop>
     <prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
</bean>

<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">

<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

--------------------------------------------------------------------------------------
web.xml部分





<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://java.sun.com/xml/ns/javaee" 
 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  
  
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>     
  </filter>
  
  <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext*.xml</param-value>
    </context-param>
    
    
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
   
</web-app>
  




------------------------------------------------------------




struts.xml




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<include file="struts-default.xml"/>
<package name="wyx.ssh" extends="struts-default" > 
<action name="Reg" class="RegAction" >
<result name="input">/reg.jsp</result>
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>




请各位大神出手相救........



关键 就是
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]



这提示 

先谢了
--------------------编程问答-------------------- 感觉是spring注入那出得问题 --------------------编程问答-------------------- 配置文件注入的有问题  --------------------编程问答-------------------- Error creating bean with name 'sessionFactory' defined in file [C:\Program Files\apache-tomcat-6.0.26\webapps\ssh\WEB-INF\classes\applicationContext.xml]

可以看看下面这个ssh  crud的例子

http://blog.csdn.net/cai5/article/details/6565523 --------------------编程问答--------------------
引用
<filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>   
  </filter>
   
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
    
  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath*:applicationContext*.xml</param-value>
  </context-param>
    
    
  <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

请将监听放在最上面,然后再加载xml配置。。注意加载的顺序。。。然后struts的配置放在最下面。

另外没看见你注入的配置。。。
--------------------编程问答-------------------- 你好,这例子里注入的有关增、删、改、查是分别把他们列出来的,而我的是采取事务管理的方式来的

--------------------编程问答-------------------- 恩 我也感觉是注入这块出错了 

这里就是接之前的web.xml其余部分
----------------------------<!-- 配置事务易做图 -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">

<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
            
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
     <prop key="update*">PROPAGATION_REQUIRED</prop>
     <prop key="delete*">PROPAGATION_REQUIRED</prop>
        <prop key="*Reg*">PROPAGATION_REQUIREED</prop>
    <prop key="*">PROPAGATION_REQUIREED,readOnly</prop>
</props>
</property>
</bean>


<!-- 定义BeanNameAutoProxyCreator -->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
 <!-- 指定对满足哪些bean name的bean 自动生成业务代理 -->
 <property name="beanNames"> 
  <list>   
  <!-- 需要自动创建事务代理的bean -->
  <value>userManager</value>
  </list>    
    <!--  此处课增加其他需要自动创建事务代理的bean-->
        </property>
        <!--   下面定义BeanNameAutoProxyCreator所需的事务易做图 -->
        <property name="interceptorNames"> 
  <list>   
    <value>transactionInterceptor</value>
  </list>   
  </property>
  </bean>
  
  
<bean id="baseDao" class="wyx.ssh.dao.BaseDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
  
  
<!-- 用户注册业务逻辑类 -->   
<bean id="userManager" class="wyx.ssh.UserManagerImpl">
<property name="dao">
<ref bean="baseDao"/>
</property>
</bean>


<!-- 用户注册地的Action -->
<bean id="RegAction" class="wyx.ssh.RegAction">
<property name="userManager">
<ref bean="userManager" />
</property>
</bean>

   --------------------编程问答-------------------- 以下是4个java类:

——————————————————————————————
package wyx.ssh;
/**
public inte易做图ce UserManager {
public void UserReg(UserForm form) throws Exception;
}


package wyx.ssh;


import org.apache.commons.beanutils.BeanUtils;
import wyx.ssh.dao.BaseDao;
import wyx.ssh.dao.BaseDaoImpl;

import wyx.ssh.dao.User;

public class UserManagerImpl implements UserManager {
private BaseDao dao;

public UserManagerImpl() {
dao=new BaseDaoImpl();
}
public void UserReg(UserForm form) throws Exception {


//构造user
User user=new User();
BeanUtils.copyProperties(user,form);

//保存user对象
dao.saveObject(user);

}

public void setDao(BaseDao dao) {
this.dao = dao;
}

}
——————————————————————

package wyx.ssh.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;


public inte易做图ce BaseDao {
public void deleteObject(Object obj) throws HibernateException;
public void deleteObject(Class class1,Serializable serializable) throws HibernateException;
public void updateObject(Object obj) throws HibernateException;
public void saveObject(Object obj) throws HibernateException;
public Object getObject(Class class1,Serializable serializable) throws HibernateException;
public List hqlQuery(String hsql) throws HibernateException;
public List hqlQuery(String hsql,Object obk) throws HibernateException;
/*public Session getSession();
public void setSession(Session session);*/

}




--------------------编程问答-------------------- 一个号只能连续回复三次.............有重要的细节要透露....... --------------------编程问答--------------------
先补全4个java类
————————————————————————
/**
   * 业务逻辑实现类
   */
 

package wyx.ssh.dao;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 


public class BaseDaoImpl extends HibernateDaoSupport implements BaseDao {




   
  
 


public void deleteObject(Object obj) throws HibernateException {
this.getHibernateTemplate().delete(obj);

}

public void deleteObject(Class class1, Serializable serializable)
throws HibernateException {
this.getHibernateTemplate().delete(this.getObject(class1, serializable));


}

public Object getObject(Class class1, Serializable serializable)
throws HibernateException {
return this.getHibernateTemplate().get(class1,serializable);

}



private List query(final String hsql,final Object obj) throws HibernateException{
int count=0;
List queryList=(List)getHibernateTemplate().execute(
new HibernateCallback(){
public Object doInHibernate(Session session)throws HibernateException,SQLException{

Query query=session.createQuery(hsql);

if(obj!=null){if (obj instanceof Map) {
String as[]=query.getNamedParameters();
for (int k1 = 0; k1 < as.length; k1++) 
query.setParameter(as[k1],((Map)obj).get(as[k1]));
}
else if(obj instanceof Object[]){
for (int i1 = 0; i1 < ((Object[])obj).length; i1++) 
query.setParameter(i1,((Object[])obj)[i1]);
}
else{
query.setParameter(0,obj);
}
}
return query.list();


     }
   }
 );
return queryList;


}

public List hqlQuery(String hsql) throws HibernateException {
// TODO Auto-generated method stub
return query(hsql,null);
}

public List hqlQuery(String hsql, Object obj) throws HibernateException {
// TODO Auto-generated method stub
return null;
}



public void saveObject(Object obj) throws HibernateException {
this.getHibernateTemplate().save(obj);

}

public void updateObject(Object obj) throws HibernateException {
this.getHibernateTemplate().update(obj);
}



}





请注意在BaseDao的接口 我注释掉了
public Session getSession();
public void setSession(Session session);
在实现BaseDao的BaseDaoImpl里
BaseDaoImpl  extends HibernateDaoSupport implements BaseDao 

因为继承了HibernateDaoSupport类,而HibernateDaoSupport已提供sessionFactory的属性和setter方法
故不必显式的声明了(这是按着书上来的)。但实际当我请注意在BaseDao的接口 我按书上来保留了在接口的
public Session getSession();
public void setSession(Session session);
不过后BaseDaoImpl也按照上面贴出来的编写后出现了错误

Multiple markers at this line
- The type BaseDaoImpl must implement the inherited abstract method 
 BaseDao.setSession(Session)
- The inherited method HibernateDaoSupport.getSession() cannot hide the 
 public abstract method in BaseDao

我解决不了 只好
/*
public Session getSession();
public void setSession(Session session);*/
这里就不报错了,现在想想 可能BaseDaoImpl继承的HibernateDaoSupport和spring之后注入的相关sessionFactory 无关 导致出现异常.................
我所理解的就是这样了,
--------------------编程问答-------------------- 我给一个我的程序的链接,耽误大家些时间下载下来帮我看下怎么处理

账号fisher346  密码123456 大家直接使用好了 省的注册了。

http://www.ctdisk.com/file/2857340
如果链接失效 也可以用这账号直接登陆下载文件


本人第一次时间SSH框架,出现个异常至今不能解决,希望各位帮下忙,帮我除掉这个心病,不胜感激!!!
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,