Spring+Struts整合问题整理

在整合的时候遇到了一些小问题,整理出来希望可以方便跟我一样的菜鸟级SSH们.

问题1现象:

2008-02-23   10:31:07,078   WARN   [org.apache.struts.action.RequestProcessor]   –   Unhandled   Exception   thrown:   class   org.springframework.beans.factory.BeanCreationException

2008-02-23   10:31:07,078   ERROR   [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myssh].[action]]   –   Servlet.service()   for   servlet   action   threw   exception

org.springframework.beans.factory.BeanCreationException:   Error   creating   bean   with   name   ‘sessionFactory’   defined   in   class   path   resource   [applicationContext.xml]:   Initialization   of   bean   failed;   nested   exception   is   org.hibernate.HibernateException:   could   not   configure   from   URL:   file:src/hibernate.cfg.xml

org.hibernate.HibernateException:   could   not   configure   from   URL:   file:src/hibernate.cfg.xml

问题一解决:

自动生成的applicationContext.xml文件配置如下:
<bean   id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property   name="configLocation">
<value> file:src/hibernate.cfg.xml </value>
</property>
</bean>

改动后的配置文件为:

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation">
        <value>classpath:/hibernate.cfg.xml</value>
    </property>
</bean>

问题2现象:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/HbmBinder$SecondPass

问题2解决:

是hibernate-a*这个包和spring有冲突,删掉hibernate-a*包就OK了

我就遇到这两个问题,希望大家不遇到问题!

问题3现象:
java.lang.IllegalStateException:   No   WebApplicationContext   found:   no   ContextLoaderListener   registered?

问题3解决:

在   web.xml中加上
<context-param>
<param-name> contextConfigLocation </param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name> context </servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: