maven+Spring+SpringMVC+Hibernate快速搭建
目录结构:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>geostack</groupId>
<artifactId>geostack-simple</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<org.springframework.version>4.3.12.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.12</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
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:default-servlet-handler /> -->
<!-- 启用spring mvc 注解 -->
<context:annotation-config /> <!-- 设置使用注解的类所在的jar包 -->
<context:component-scan base-package="com.geostar.gfstack.operationcenter.*.action,com.geostar.gfstack.operationcenter.*.*.action,com.geostar.gfstack.operationcenter.*.*.*.action,com.geostar.gfstack.operationcenter.*.*.*.*.action"></context:component-scan>
<!-- 自动注入处理器映射器和适配器 和springmvc拦截器-->
<mvc:annotation-driven></mvc:annotation-driven> <!-- 完成请求和注解POJO的映射
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
--> <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/platform/" />
<property name="suffix" value=".jsp" />
</bean> <!-- 上传文件MultipartResolver处理器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
<property name="maxUploadSize" value="1024000"></property>
</bean> </beans>
applicationContext-database.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>${jdbc.driver}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="maxActive">
<value>${jdbc.maxActive}</value>
</property>
<property name="maxIdle">
<value>${jdbc.maxIdle}</value>
</property>
<property name="maxWait">
<value>${jdbc.maxWait}</value>
</property>
<property name="logAbandoned">
<value>${jdbc.logAbandoned}</value>
</property>
<property name="removeAbandoned">
<value>${jdbc.removeAbandoned}</value>
</property>
<property name="removeAbandonedTimeout">
<value>${jdbc.removeAbandonedTimeout}</value>
</property>
<property name="testWhileIdle">
<value>${jdbc.testWhileIdle}</value>
</property>
<property name="timeBetweenEvictionRunsMillis">
<value>${jdbc.timeBetweenEvictionRunsMillis}</value>
</property>
<property name="validationQuery">
<value>${jdbc.validationQuery}</value>
</property>
</bean> <!-- Hibernate配置 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.query.factory_class">
${hibernate.query.factory_class}
</prop>
<prop key="current_session_context_class">
${current_session_context_class}
</prop>
<prop key="hibernate.hbm2ddl.auto">
update
</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<!-- 添加解析XML的扫描路径 -->
<value>com.geostar.gfstack.operationcenter.simple.model</value>
</list>
</property>
</bean> <bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="globalRollbackOnParticipationFailure" value="false"/>
</bean> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="use*" propagation="REQUIRED"/>
<tx:method name="freed*" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice> <aop:config>
<aop:advisor
pointcut="execution(* com.geostar.gfstack.operationcenter.*.service.*Service.*(..))"
advice-ref="txAdvice"/>
<aop:advisor
pointcut="execution(* com.geostar.gfstack.operationcenter.*.*.service.*Service.*(..))"
advice-ref="txAdvice"/>
<aop:advisor
pointcut="execution(* com.geostar.gfstack.operationcenter.*.*.*.service.*Service.*(..))"
advice-ref="txAdvice"/>
<aop:advisor
pointcut="execution(* com.geostar.gfstack.operationcenter.*.*.*.*.service.*Service.*(..))"
advice-ref="txAdvice"/>
</aop:config> </beans>
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: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/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.geostar.gfstack.operationcenter"/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/GeoStar.properties</value>
</list>
</property>
</bean>
<import resource="classpath:config/spring/applicationContext-database.xml"/> </beans>
GeoStar.properties
#MySQL|Oracle
#jdbc.db.type=Oracle
jdbc.db.type=Mysql #apache dbcp jdbc
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://db-exte.gfstack.geo\:3306/operationcenter
jdbc.username=gfstack
jdbc.password=gfstack jdbc.maxActive=10
jdbc.maxIdle=3
jdbc.maxWait=500
jdbc.logAbandoned=false
jdbc.removeAbandoned=true
jdbc.removeAbandonedTimeout=5000
jdbc.timeBetweenEvictionRunsMillis=120000
jdbc.testWhileIdle=true
jdbc.validationQuery=select 1 from dual hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=false
hibernate.query.factory_class=org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
current_session_context_class=thread
log4j.properties
log4j.rootLogger=INFO,CONSOLE,APPLOG log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c %x - %m%n log4j.appender.APPLOG=org.apache.log4j.DailyRollingFileAppender
log4j.appender.APPLOG.File=${catalina.home}/logs/geostack-simple.log
log4j.appender.APPLOG.DatePattern='.'yyyy-MM-dd
log4j.appender.APPLOG.Append=true
log4j.appender.APPLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.APPLOG.layout.ConversionPattern=[%d{yyyy-MM-dd hh:mm:ss}]-[%5p] [%l] %m%n log4j.logger.com.geostar.gfstack=ALL,CONSOLE,APPLOG
log4j.logger.com.geostar.geostack=ALL,CONSOLE,APPLOG
log4j.additivity.com.geostar.gfstack=false
log4j.additivity.com.geostar.geostack=false
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"
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"> <display-name>geostack-dispatch</display-name> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener> <servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> </web-app>
SimpleAction.java
package com.geostar.gfstack.operationcenter.simple.action; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter; @Controller
@RequestMapping("simpleAction")
public class SimpleAction { @ResponseBody
@RequestMapping("test")
public void test(){
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
response.setHeader("Content-type", "text/html;charset=utf-8");
PrintWriter write = null;
try {
write = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
write.print("test");
} }
maven+Spring+SpringMVC+Hibernate快速搭建的更多相关文章
- javaweb各种框架组合案例(三):maven+spring+springMVC+hibernate
1.hibernate译为"越冬",指的是给java程序员带来春天,因为java程序员无需再关心各种sql了: 2.hibernate通过java类生成数据库表,通过操作对象来映射 ...
- spring+springmvc+hibernate 框架搭建
1.新建web项目,将所需jar包放到 lib 目录下 2.配置web.xml 配置文件 <?xml version="1.0" encoding="UTF-8&q ...
- Maven搭建简单的SPring+SpringMVC+Hibernate框架
公司的项目用到的框架是Spring+SpringMVC+Hibernate 以前没有用过,所以要系统的学习一下,首先要学会怎么搭建 第一步 创建一个Maven的web项目 创建方法以前的博客中有提 ...
- 用Eclipse 搭建一个Maven Spring SpringMVC 项目
1: 先创建一个maven web 项目: 可以参照之前的文章: 用Maven 创建一个 简单的 JavaWeb 项目 创建好之后的目录是这样的; 2: 先配置maven 修改pom.xml & ...
- spring+springmvc+hibernate架构、maven分模块开发样例小项目案例
maven分模块开发样例小项目案例 spring+springmvc+hibernate架构 以用户管理做測试,分dao,sevices,web层,分模块开发測试!因时间关系.仅仅測查询成功.其它的准 ...
- 框架篇:Spring+SpringMVC+hibernate整合开发
前言: 最近闲的蛋疼,搭个框架写成博客记录下来,拉通一下之前所学知识,顺带装一下逼. 话不多说,我们直接步入正题. 准备工作: 1/ IntelliJIDEA的安装配置:jdk/tomcat等..(本 ...
- spring+springmvc+hibernate 整合
三大框架反反复复搭了很多次,虽然每次都能搭起来,但是效率不高.最近重新搭了一次,理顺了思路,整理了需要注意的地方,分享出来. 工具:Eclipse(jdk 1.7) spring和hibernate版 ...
- IntelliJ IDEA 使用maven 集成SpringMVC+Hibernate
准备工作: 安装idea intellij 安装jdk1.8,配好环境变量 安装tomcat 7 准备工作完成之后,就开始创建项目了 创建项目 1.File–>new project–>选 ...
- 笔记48 Spring+SpringMVC+Hibernate整合
搭建Spring+SpringMVC+Hibernate的框架的思路如下: 1.创建Maven项目,按需映入Maven包依赖. 2.搭建Spring:配置Spring对控件层Bean的注入. 3.搭建 ...
随机推荐
- Java8-1-新特性_Lambda表达式
最近实在是闲的蛋疼, 突然想起前一段时间使用Lambda表达式觉得惊为天人, 所以就去仔细的学习了一下, 整理出一份博客出来供大家观赏. 一. 什么是lambda表达式. Lambda 是一个匿名函数 ...
- Android如果有一个任意写入的漏洞,如何将写权限转成执行权限
这个题目我以为是考的怎么进行提权,结果原来是这样的: . DexClassLoader 动态载入应用可写入的 dex 可执行文件 . java.lang.Runtime.exec 方法执行应用可写入的 ...
- 模块的语法 import ,from...import....
------------------------积极的人在每一次忧患中都看到一个机会, 而消极的人则在每个机会都看到某种忧患 1. 认识模块 模块可以认为是一个py文件. 模块实际上是我们的py文件运 ...
- elasticsearch开启外网访问
默认情况下,Elastic 只允许本机访问,如果需要远程访问,可以修改 Elastic 安装目录的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改成 ...
- Centos7 下SVN迁移
SVN迁移需要做如下操作: 1. 将原来的Repository导出 . #svnadmin dump 原有repos的目录路径 > dumpfile (不同服务器安装目录不同,根据具体情况调整) ...
- java中scanner的正确用法
Scanner s = new Scanner(System.in); int choice = 0; if(s.hasNextInt()) { choice = s.nextInt(); } s.c ...
- 浅谈一类无关序列有前缀和性质的统计问题的离线解法 BZOJ3626
每次询问[l,r]区间,但所有信息是按另一种序列给出的,因此无法使用区间数据结构做这种题.将每个询问改为[1,x],考虑离线,则从1~n依次修改并查询即可. BZOJ3626 给定一颗树,每次询问给定 ...
- SDK安装详解以及adb的来源
首先,下载Android SDK Tools,翻过墙的朋友可以去Google Android的官网上下载(http://developer.android.com/sdk/index.html) 选择 ...
- semantic-ui 输入框
1.标准输入框 semantic-ui中定义输入框需要将input标签包含于另外一个标签内,外层标签的class为ui input,注意外层标签可以是div,span.p.i. <div cla ...
- html js 表单提交前检测数据
通过使用form的onsibmit来控制是否提交数据 返回值为真是提交,其他不变,示例如下: JS部分 function check() { var newPwd = document.getElem ...