wifi优酷版权受限限怎么办

eclipse 手动搭建ssh框架(spring整合struts,spring 整合hibernate) - 黑。 - ITeye技术网站
博客分类:
很开心,今天终于在eclipse手动的搭建好了SSH框架。在此记录下来待以后继续学习。
很开心,今天终于在eclipse手动的搭建好了SSH框架。在此记录下来待以后继续学习。
1, spring整合struts
首先在web.xml里添加上
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
/WEB-INF/applicationContext*.xml
&!-- Spring Framework --&
&listener&
&listener-class&
org.springframework.web.context.ContextLoaderListener
&/listener-class&
&/listener&
&context-param&
&param-name&contextConfigLocation&/param-name&
&!-- applicationContext.xml路径 --&
&param-value&/WEB-INF/applicationContext*.xml&/param-value&
&/context-param&
在struts.xml里(以简单登陆为例)
name="default" extends="struts-default"
name="Login" class="loginAction"
name="success"/WEB-INF/CONTENT/common/homePage.jsp
name="error"/WEB-INF/CONTENT/common/error.jsp
name="INPUT"/WEB-INF/CONTENT/common/Login.jsp
&!-- 配置了系列常量 --&
&package name="default" extends="struts-default"&
&!-- common action 其中class里应该是spring 中bean 的id--&
&action name="Login" class="loginAction"&
&result name="success"&/WEB-INF/CONTENT/common/homePage.jsp&/result&
&result name="error"&/WEB-INF/CONTENT/common/error.jsp&/result&
&result name="INPUT"&/WEB-INF/CONTENT/common/Login.jsp&/result&
&/package&
在applicationContext.xml中
version="1.0" encoding="UTF-8"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
name="loginService" class="com.nwu.hrsystem.service.impl.LoginServiceImpl"
id="loginAction" class="com.nwu.hrsystem.action.LoginAction"
scope="prototype"
name="loginService" ref="loginService"
&?xml version="1.0" encoding="UTF-8"?&
&beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&
&bean name="loginService" class="com.nwu.hrsystem.service.impl.LoginServiceImpl"&
&!-- Action 注入给Service --&
&bean id="loginAction" class="com.nwu.hrsystem.action.LoginAction"
scope="prototype"&
&property name="loginService" ref="loginService"&&/property&
我们可以在LoginServiceImpl里写个验证代码检验一下。2,spring整合hibernate
在applicationContext.xml里添加上
&!-- 设置连接数据库的驱动、URL、用户名、密码
连接池最大连接数、最小连接数、初始连接数等参数 --
id="dataSource" class="com.mchange.boPooledDataSource"
destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost:3306/myhrSystem"
p:user="root"
p:password="1"
p:maxPoolSize="40"
p:minPoolSize="1"
p:initialPoolSize="1"
p:maxIdleTime="20"
id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
name="mappingResources"
com/nwu/hrsystem/beans/User.hbm.xml
name="hibernateProperties"
&!-- 指定数据库方言、是否自动建表
是否生成SQL语句等
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true
#开启二级缓存
hibernate.cache.use_second_level_cache=true
#设置二级缓存的提供者
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
&!-- 定义数据源Bean,使用C3P0数据源实现 --&
&!-- 设置连接数据库的驱动、URL、用户名、密码
连接池最大连接数、最小连接数、初始连接数等参数 --&
&bean id="dataSource" class="com.mchange.boPooledDataSource"
destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost:3306/myhrSystem"
p:user="root"
p:password="1"
p:maxPoolSize="40"
p:minPoolSize="1"
p:initialPoolSize="1"
p:maxIdleTime="20"/&
&!-- 定义Hibernate的SessionFactory --&
&!-- 依赖注入数据源,注入正是上面定义的dataSource --&
&bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"&
&!-- mappingResouces属性用来列出全部映射文件 --&
&property name="mappingResources"&
&!-- 以下用来列出Hibernate映射文件 --&
&value&com/nwu/hrsystem/beans/User.hbm.xml&/value&
&/property&
&!-- 定义Hibernate的SessionFactory的属性 --&
&property name="hibernateProperties"&
&!-- 指定数据库方言、是否自动建表
是否生成SQL语句等
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true
#开启二级缓存
hibernate.cache.use_second_level_cache=true
#设置二级缓存的提供者
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
&/property&
在User.hbm.xml中要注意与PO类User.java 里定义的各种属性及数据库要对应,不然会出错
这样SSH框架就搭建好了,我们可以用一个简单的登陆系统的例子检验一下:
完整的配置文件
version="1.0" encoding="UTF-8"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="/xml/ns/javaee" xmlns:web="/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="/xml/ns/javaee /xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
/WEB-INF/applicationContext*.xml
/WEB-INF/CONTENT/common/Login.jsp
&?xml version="1.0" encoding="UTF-8"?&
&web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="/xml/ns/javaee" xmlns:web="/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="/xml/ns/javaee /xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&
&display-name&HRSystem&/display-name&
&!-- Struts 2 Filter --&
&filter-name&struts2&/filter-name&
&filter-class&org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&/filter-class&
&filter-mapping&
&filter-name&struts2&/filter-name&
&url-pattern&/*&/url-pattern&
&/filter-mapping&
&!-- Spring Framework --&
&listener&
&listener-class&
org.springframework.web.context.ContextLoaderListener
&/listener-class&
&/listener&
&context-param&
&param-name&contextConfigLocation&/param-name&
&!-- applicationContext.xml路径 --&
&param-value&/WEB-INF/applicationContext*.xml&/param-value&
&/context-param&
&!-- welcome file --&
&welcome-file-list&
&welcome-file&/WEB-INF/CONTENT/common/Login.jsp&/welcome-file&
&/welcome-file-list&
&/web-app&
struts.xml
version="1.0" encoding="UTF-8"
&!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd"
name="default" extends="struts-default"
name="Login" class="loginAction"
name="success"/WEB-INF/CONTENT/common/homePage.jsp
name="error"/WEB-INF/CONTENT/common/error.jsp
&?xml version="1.0" encoding="UTF-8"?&
&!-- 指定Struts2配置文件的DTD信息 --&
&!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd"&
&!-- Struts2配置文件的根元素 --&
&!-- 配置了系列常量 --&
&package name="default" extends="struts-default"&
&!-- common action --&
&action name="Login" class="loginAction"&
&result name="success"&/WEB-INF/CONTENT/common/homePage.jsp&/result&
&result name="error"&/WEB-INF/CONTENT/common/error.jsp&/result&
&/package&
applicationContext.xml
version="1.0" encoding="UTF-8"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
&!-- 设置连接数据库的驱动、URL、用户名、密码
连接池最大连接数、最小连接数、初始连接数等参数 --
id="dataSource" class="com.mchange.boPooledDataSource"
destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost:3306/myhrSystem"
p:user="root"
p:password="1"
p:maxPoolSize="40"
p:minPoolSize="1"
p:initialPoolSize="1"
p:maxIdleTime="20"
id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
name="mappingResources"
com/nwu/hrsystem/beans/User.hbm.xml
name="hibernateProperties"
&!-- 指定数据库方言、是否自动建表
是否生成SQL语句等
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true
#开启二级缓存
hibernate.cache.use_second_level_cache=true
#设置二级缓存的提供者
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
id="employeeDao" class="com.nwu.hrsystem.dao.impl.EmployeeDaoImpl"
name="sessionFactory"
bean="sessionFactory"
name="loginService" class="com.nwu.hrsystem.service.impl.LoginServiceImpl"
name="employeeDao"
bean="employeeDao"
id="loginAction" class="com.nwu.hrsystem.action.LoginAction"
scope="prototype"
name="loginService" ref="loginService"
&?xml version="1.0" encoding="UTF-8"?&
&beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&
&!-- 定义数据源Bean,使用C3P0数据源实现 --&
&!-- 设置连接数据库的驱动、URL、用户名、密码
连接池最大连接数、最小连接数、初始连接数等参数 --&
&bean id="dataSource" class="com.mchange.boPooledDataSource"
destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost:3306/myhrSystem"
p:user="root"
p:password="1"
p:maxPoolSize="40"
p:minPoolSize="1"
p:initialPoolSize="1"
p:maxIdleTime="20"/&
&!-- 定义Hibernate的SessionFactory --&
&!-- 依赖注入数据源,注入正是上面定义的dataSource --&
&bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"&
&!-- mappingResouces属性用来列出全部映射文件 --&
&property name="mappingResources"&
&!-- 以下用来列出Hibernate映射文件 --&
&value&com/nwu/hrsystem/beans/User.hbm.xml&/value&
&/property&
&!-- 定义Hibernate的SessionFactory的属性 --&
&property name="hibernateProperties"&
&!-- 指定数据库方言、是否自动建表
是否生成SQL语句等
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true
#开启二级缓存
hibernate.cache.use_second_level_cache=true
#设置二级缓存的提供者
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
&/property&
&!-- Dao 注入session 工厂 --&
&bean id="employeeDao" class="com.nwu.hrsystem.dao.impl.EmployeeDaoImpl"&
&property name="sessionFactory"&
&ref bean="sessionFactory"&&/ref&
&/property&
Service 注入给Dao --&
&bean name="loginService" class="com.nwu.hrsystem.service.impl.LoginServiceImpl"&
&property name="employeeDao"&
&ref bean="employeeDao"&&/ref&
&/property&
&!-- Action 注入给Service --&
&bean id="loginAction" class="com.nwu.hrsystem.action.LoginAction"
scope="prototype"&
&property name="loginService" ref="loginService"&&/property&
User.hbm.xml
version="1.0" encoding="UTF-8"
&!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"
package="com.nwu.hrsystem.beans"
name="User" table="user_tab"
discriminator-value="1"
usage="read-only"
name="user_id" type="java.lang.Integer" column="user_id"
class="native"
name="user_name" column="user_name" type="java.lang.String"
not-null="true" length="15"
name="user_pwd" column="user_pwd"
type="java.lang.String"
not-null="true" length="15"
&?xml version="1.0" encoding="UTF-8"?&
&!-- 指定Hibernate映射文件的DTD信息 --&
&!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&
&!-- Hibernate映射文件的根元素 --&
&hibernate-mapping package="com.nwu.hrsystem.beans"&
&class name="User" table="user_tab"
discriminator-value="1"&
&!-- 使用只读缓存 --&
&cache usage="read-only"/&
&!-- 映射标识属性 --&
&id name="user_id" type="java.lang.Integer" column="user_id"&
&!-- 指定使用native主键生成策略 --&
&generator class="native"/&
&!-- 映射普通属性 --&
&property name="user_name" column="user_name" type="java.lang.String"
not-null="true" length="15" /&
&property name="user_pwd" column="user_pwd" type="java.lang.String"
not-null="true" length="15"/&
&/hibernate-mapping&
值得注意的是:User.java文件里首先其定义的成员变量的类型要和数据库里数据表里的每列的类型要一样。其次其成员变量要设定get,set方法。
在action层里声明service层时,在service层声明Dao层时也需要添加get,set方法 且其引用名得和spring配置文件里各层bean里property的name属性要一致。
比如在action里定义了个 private LoginService loginS 然后就要给其添加get,set方法。并且在applicationContext.xml中,
id="loginAction" class="com.nwu.hrsystem.action.LoginAction"
scope="prototype"
name="loginService" ref="loginService"
&bean id="loginAction" class="com.nwu.hrsystem.action.LoginAction"
scope="prototype"&
&property name="loginService" ref="loginService"&&/property&
在搭建框架时我遇到过这样的一个异常:
Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation o nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
在网上查了很多资料有人说是缺jar包,有人说是配置文件有问题。经过我细细排查发现在User.hbm.xml文件里的一个user_pwd属性列里我写成了uesr_pwd,修改过后,终于跑通了。所以在我们写这类文件时千万要注意,不能写错,不然的话又要花很多时间来检查。
shaohan126448
浏览: 66234 次
来自: 北京
你好,能将demo源码发我下吗?jackclchan@qq.c ...
你好,能将demo源码发我下吗?@qq.co ...
你好,上面的demo 能发我一份了
deshanjiang8 ...
spring mvc demo教程源代码下载,地址:http: ...主题信息(必填)
主题描述(最多限制在50个字符)
申请人信息(必填)
申请信息已提交审核,请注意查收邮件,我们会尽快给您反馈。
如有疑问,请联系
关注大数据、云计算、人工智能、IoT、移动开发领域
爱好编程,上手快,学习能力强,阅读文档,对log、error信息良好的嗅觉
深圳码农一枚,专注嵌入式移动, Linux, OS, Tcp/ip, Android
详细描述如何在eclipse使用maven搭建spring本帖子已过去太久远了,不再提供回复功能。一、安装Spring Tool Suite插件
点击Finish之后等待安装,安装完之后弹窗点击yes重启Eclipse,重启后显示如下界面:
二、搭建Spring开发环境
1.导入jar包到工程的ClassPath下 & & x.x.x为版本号
  commons-logging-x.x.x.jar & & & --------》Spring的依赖包
  spring-beans-x.x.x.RELEASE.jar
  spring-context-x.x.x.RELEASE.jar
  spring-core-x.x.x.RELEASE.jar
  spring-expression-x.x.x.RELEASE.jar
2.  接下来就可以直接创建基于的Spring项目了
阅读(...) 评论()

我要回帖

更多关于 优酷版权受限无法观看 的文章

 

随机推荐