目录结构:

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快速搭建的更多相关文章

  1. javaweb各种框架组合案例(三):maven+spring+springMVC+hibernate

    1.hibernate译为"越冬",指的是给java程序员带来春天,因为java程序员无需再关心各种sql了: 2.hibernate通过java类生成数据库表,通过操作对象来映射 ...

  2. spring+springmvc+hibernate 框架搭建

    1.新建web项目,将所需jar包放到 lib 目录下 2.配置web.xml 配置文件 <?xml version="1.0" encoding="UTF-8&q ...

  3. Maven搭建简单的SPring+SpringMVC+Hibernate框架

    公司的项目用到的框架是Spring+SpringMVC+Hibernate 以前没有用过,所以要系统的学习一下,首先要学会怎么搭建 第一步  创建一个Maven的web项目  创建方法以前的博客中有提 ...

  4. 用Eclipse 搭建一个Maven Spring SpringMVC 项目

    1: 先创建一个maven web  项目: 可以参照之前的文章:  用Maven 创建一个 简单的 JavaWeb 项目 创建好之后的目录是这样的; 2: 先配置maven  修改pom.xml & ...

  5. spring+springmvc+hibernate架构、maven分模块开发样例小项目案例

    maven分模块开发样例小项目案例 spring+springmvc+hibernate架构 以用户管理做測试,分dao,sevices,web层,分模块开发測试!因时间关系.仅仅測查询成功.其它的准 ...

  6. 框架篇:Spring+SpringMVC+hibernate整合开发

    前言: 最近闲的蛋疼,搭个框架写成博客记录下来,拉通一下之前所学知识,顺带装一下逼. 话不多说,我们直接步入正题. 准备工作: 1/ IntelliJIDEA的安装配置:jdk/tomcat等..(本 ...

  7. spring+springmvc+hibernate 整合

    三大框架反反复复搭了很多次,虽然每次都能搭起来,但是效率不高.最近重新搭了一次,理顺了思路,整理了需要注意的地方,分享出来. 工具:Eclipse(jdk 1.7) spring和hibernate版 ...

  8. IntelliJ IDEA 使用maven 集成SpringMVC+Hibernate

    准备工作: 安装idea intellij 安装jdk1.8,配好环境变量 安装tomcat 7 准备工作完成之后,就开始创建项目了 创建项目 1.File–>new project–>选 ...

  9. 笔记48 Spring+SpringMVC+Hibernate整合

    搭建Spring+SpringMVC+Hibernate的框架的思路如下: 1.创建Maven项目,按需映入Maven包依赖. 2.搭建Spring:配置Spring对控件层Bean的注入. 3.搭建 ...

随机推荐

  1. Docker资源限制与Cgroups

    一.Linux control groups 简介     Linux CGroup全称Linux Control Group, 是Linux内核的一个功能,用来限制,控制与分离一个进程组群的资源(如 ...

  2. Maven学习第4期---Maven简单使用

    一.Maven常用命令 在学习使用Maven构建项目之前,先来了解一下Maven一些实用的命令.mvn的命令有很多,在项目开发中,理解了下面的几个常用命令后,运用maven就基本没有问题了.Maven ...

  3. FineUIMvc随笔(3)不能忘却的回发(__doPostBack)

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户反馈 有网友在官方论坛抛出了这么一个问题,似乎对 FineUIMvc 中的浏览器端与服务器端的交互方式很有异议. 这里面的关 ...

  4. <<.NET B/S 架构实践>> 几种概念区别 - 算法、设计模式、企业应用架构模式、架构模式

    算法:相信大家对算法肯定不陌生(但其实绝大多数开发人员对这个非常陌生且抗拒),因为从学校没毕业开始就已经被算法折磨了,哈哈 设计模式:爱学习的开发人员对这个也不会陌生,是些到了一定工作阶段必须学的思想 ...

  5. Flask发送邮件

    参考:官方文档:https://pythonhosted.org/Flask-Mail/ 1.安装插件  Flask-Mail (pip install Flask-Mail) 2.配置 Flask- ...

  6. Sql Server中的nvarchar(n)、varchar(n) 和Mysql中的char(n)、varchar(n)

    刚才有幸看了下 nvarchar(n)和varchar(n),感觉以前的认知有误. nvarchar(n):n指的是字符个数,范围是1-4000,存储的是可变长度的Unicode字符数据. 按字符存储 ...

  7. H5 67-清除浮动方式三

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. UnderWater+SDN论文之六

    Protocol Emulation Platform Based on Microservice Architecture for Underwater Acoustic Networks Sour ...

  9. vue上传图片

    在用这块代码前需要在主页面index引入<script src="http://at.alicdn.com/t/font_kfbh2nlnqrrudi.js">< ...

  10. Azure系列2.1.4 —— BlobInputStream

    (小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...