您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > Spring搭建出现HTTPStatus404解决方案
1出现HTTPStatus404是我们不一步一步创建工程,创建步骤如下在工程中应用Spring一、创建一个项目“ssh-1”项目利用之前的工程“hibernate-Criteria-EHCache”,在其中添加Spring框架,成为“ssh-1”工程。首先创建工程“ssh_1”。说明:创建SSH项目时,第一步就是编写web.xml文件,除了添加Struts框架外,还要添加监听器,监听所有的动作。二、编写web.xml文件除了添加Struts框架外,还需要添加Spring的监听器,监听所有动作。添加listener标签:listenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listener再增加一个登录配置项标签login-config,设置基本登录方式“BASIC”:login-configauth-methodBASIC/auth-method/login-configweb.xml文件内容为:?xmlversion=1.0encoding=UTF-8?web-appversion=2.5xmlns=:xsi=:schemaLocation=://java.sun.com/xml/ns/javaee/web-app_2_5.xsdfilterfilter-namestruts2/filter-namefilter-classorg.apache.struts2.dispatcher.FilterDispatcher/filter-class/filterfilter-mappingfilter-namestruts2/filter-nameurl-pattern/*/url-pattern2/filter-mappinglistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listenerwelcome-file-listwelcome-fileindex.jsp/welcome-file/welcome-file-listlogin-configauth-methodBASIC/auth-method/login-config/web-app三、拷入已有的包和文件把“hibernate-Criteria-EHCache”中的所有引用的jar包拷入“ssh-1”工程中;添加Struts支持Spring的插件:“struts2-spring-plugin-2.0.14.jar”(在课件文件夹中有);把“hibernate-Criteria-EHCache”中src目录下的配置文件拷入“ssh-1”工程中;把“hibernate-Criteria-EHCache”中src目录下各个包和其中的类拷入“ssh-1”工程中。四、用反向工程向项目中添加Spring2.0类库右击工程名→“MyEclipse”:3选“Spring2.0”;选“CopycheckedLibrarycontentstoprojectfolder”;并选模块:第1、2、3、4、11项:4NextBrowse找到WebRoot\WEB-INF:5Ok6Finish五、解决包冲突问题点开项目的引用库文件夹,看到有同名的包,会有冲突,在工作空间中项目的lib文件夹中,需要手工进行删除:asm-2.2.3.jar(Spring2.0的)与asm.jar(Hibernate3.2的)冲突,删除:asm-2.2.3.jar。cglib-nodep-2.1.3.jar(Spring2.0的)与cglib-2.1.3.jar(Hibernate3.2的)冲突,删除:cglib-2.1.3.jar。然后刷新项目。7六、改写WebRoot\WEB-INF\applicationContext.xml文件将Hibernate的数据源和SessionFactory交给Spring管理,根据“hibernate.cfg.xml”中的内容,添加为“applicationContext.xml”文件中的配置代码,两者内容对比如下:1、原hibernate.cfg.xml的代码为:?xmlversion=1.0encoding=UTF-8?!DOCTYPEhibernate-configurationPUBLIC-//Hibernate/HibernateConfigurationDTD3.0//EN=connection.driver_classcom.mysql.jdbc.Driver/propertypropertyname=connection.urljdbc:mysql://127.0.0.1:3306/BOOKS/propertypropertyname=connection.usernameroot/propertypropertyname=connection.passwordroot/propertypropertyname=connection.pool_size100/propertypropertyname=dialectorg.hibernate.dialect.MySQLDialect/propertypropertyname=current_session_context_classthread/propertypropertyname=transaction.flush_before_completiontrue/propertypropertyname=transaction.auto_close_sessiontrue/propertypropertyname=connection.release_modeon_close/propertypropertyname=hibernate.cache.use_second_level_cachetrue/propertypropertyname=hibernate.cache.provider_classorg.hibernate.cache.EhCacheProvider/propertymappingresource=com/po/BookPO.hbm.xml//session-factory/hibernate-configuration2、把对应内容添加到applicationContext.xml中,代码为:?xmlversion=1.0encoding=UTF-8?beansxmlns=:xsi=:schemaLocation=://以下为添加的内容:beanid=dataSourceclass=org.apache.commons.dbcp.BasicDataSourcepropertyname=driverClassNamevalue=com.mysql.jdbc.Driver/propertypropertyname=urlvalue=jdbc:mysql://127.0.0.1:3306/BOOKS/propertypropertyname=usernamevalue=root/propertypropertyname=passwordvalue=root/propertypropertyname=maxActivevalue=100/propertypropertyname=maxIdlevalue=30/propertypropertyname=maxWaitvalue=500/propertypropertyname=defaultAutoCommitvalue=true/property/beanbeanid=sessionfactoryclass=org.springframework.orm.hibernate3.LocalSessionFactoryBeanpropertyname=dataSourceref=dataSource/propertypropertyname=hibernatePropertiespropspropkey=hibernate.dialectorg.hibernate.dialect.MySQLDialect/proppropkey=hibernate.current_session_context_classtthread/proppropkey=hibernate.transaction.flush_before_completiontrue/proppropkey=hibernate.transaction.auto_close_sessiontrue/proppropkey=hibernate.connection.release_modeon_close/proppropkey=hibernate.cache.use_second_level_cachetrue/proppropkey=hibernate.cache.provider_classorg.hibernate.cache.EhCacheProvider/prop/props/propertypropertyname=mappingResourceslistvaluecom/po/BookPO.hbm.xml/value/list/property/bean/beans共有两段bean标签:第一段为配置数据源,第二段为配置SessionFactory。3、清空hibernate.cfg.xml文件中session-factory标签中的内容因为今后SessionFactory由Spring接管,不再由Hibernate直接管理,清空后的hibernate.cfg.xml文件内容为:9?xmlversion=1.0encoding=UTF-8?!DOCTYPEhibernate-configurationPUBLIC-//Hibernate/HibernateConfigurationDTD3.0//EN
本文标题:Spring搭建出现HTTPStatus404解决方案
链接地址:https://www.777doc.com/doc-2850107 .html