SSSP框架整合之路
来源:互联网 发布:json null 编辑:程序博客网 时间:2024/06/03 20:59
SSSP是:SpringMvc,Spring,SpringData,JPA(hibernate)的整合
第一步:创建web项目工程文件,导入所需jar包
第二步:配置web.xml的文件
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <!--配置SpringMVC--> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--配置Spring--> <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>第二步:配置数据库db.peoperties
db.driver=com.mysql.jdbc.Driverdb.url=jdbc:mysql://localhost:3306/japdb.username=rootdb.password=root
第三步:配置SpringMvc的配置文件spring-servlet.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" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:annotation-driven/> <!--配置注解--> <context:component-scan base-package="org.peter" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!--配置视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean></beans>
第四步:配置SpringMvc的配置文件applicationContext.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" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--配置扫描的service--> <context:component-scan base-package="org.peter" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/> </context:component-scan> <!--配置数据源--> <context:property-placeholder location="classpath:db.properties"/> <bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource"> <property name="driverClassName" value="${db.driver}"/> <property name="url" value="${db.url}"/> <property name="username" value="${db.username}"/> <property name="password" value="${db.password}"/> </bean> <!--配置JPA,,替代之前JPA中的persistence.xml文件--> <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> <property name="dataSource" ref="dataSource"/> <!--配置JPA的实现类的适配器--> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/> </property> <!--配置所有Model的位置--> <property name="packagesToScan" value="org.peter.model"></property> <property name="jpaProperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <!--配置Spring Data,base-package表示要扫描的包--> <jpa:repositories base-package="org.peter.dao" entity-manager-factory-ref="entityManagerFactory"></jpa:repositories> <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <!--配置事物--> <tx:annotation-driven transaction-manager="transactionManager"/></beans>
第五步:测试配置的环是否可用
只需通过这五步就可以完成SSSP的整合
空白的SSSP框架的代码:http://download.csdn.net/detail/strive_peter/9916238
阅读全文
0 0
- SSSP框架整合之路
- sssp整合&分页之分页操作
- sssp整合&分页之完成添加
- sssp整合分页之完成删除操作
- sssp整合分页之完成修改操作(三)【具体操作】
- SSSP整合&&分页&&CRUD
- SSSP整合:Context initialization failed
- sssp整合&分页之完成添加操作之显示页面&使用JPA二级缓存
- sssp整合&分页之完成添加操作之Ajax 验证用户名可用性
- sssp整合分页之完成修改操作(一)【表单回显】
- sssp整合分页之完成修改操作(二)【修改状态下Ajax验证用户名可用性】
- SSM框架的整合之路
- SSH框架的整合之路
- SSH2之框架整合
- SSM之框架整合
- ssh框架整合之spring整合
- ssh框架整合之hibernate整合
- SSH整合之框架搭建
- 鼠标、手指拖曳物体移动
- gettimeofday()函数的使用方法
- JDBC的事务处理
- JavaScript的几种Math函数,random(),ceil(),round(),floor()
- 手把手用 IntelliJ IDEA 和 SBT 创建 scala 项目
- SSSP框架整合之路
- jira安装
- leveldb(九):log::Reader读日志
- node接收get与post请求
- 全栈式PHP集成环境-laragon(一)介绍、安装
- 23种设计模式
- 了解负载均衡 会话保持 session同步(转)
- Error dropping database (can't rmdir './xxxxxxx/', errno: 17)
- 利用 livy 远程提交 spark作业