maven初始搭建一个基础项目(spring mvc+spring+jdbc mysql+jstl)
技术选型:
一.项目搭建:
1)创建maven项目 (我博客里面有介绍)
选择aptach的maven-archetype-webapp
填入groupIDhe artifactId等
确认项目名称
maven插件会自动生成项目结构
2)添加其他目录
在/src/main下添加java目录(命名自己定),设置为源码根目录
注:有需要的话可以在src目录下添加测试相关代码的目录
建立如下目录结构(自己定)
com.xx.common
com.xx.vip
.entity
.dao
.function
.web
-formbean
-handler
在webapp下建立static(放静态资源) 在webapp/WEB-INF/views(放jsp页面)
注意:web.xml版本头一定是3.0以上的
3)修改项目和模块的语言级别为java1.8
默认的LanguageLevel和JavaCompiler都是1.5
需要在pom.xml中添加如下代码,制定maven变异插件maven-compiler-plugin的版本
在<build>标签中设置
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<plugin>
<plugins>
二.集成springMVC
在http://mvnrepository.com/网站搜索依赖库
1)在pom.xml中添加依赖
spring-mvc
servlet-api
jstl
2)在src/main/resources目录下添加spring-mvc.xml配置文件
a)添加注解驱动<mvc:annotation-driven />
b)注册视图解析器
c) 扫描mvc组件
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd"> <!-- 使用注解来请求映射 -->
<mvc:annotation-driven/> <!-- 配置自动扫描包 -->
<context:component-scan base-package="com.cc8w.Controller"></context:component-scan> <bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 重定向是否添加上下文路径-->
<property name="redirectContextRelative" value="true"></property>
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean> </beans>
3)在web.xml中配置spring-mvc前端控制器DispatcherServlet
a)配置随服务启动而初始化
b)配置参数contextConfigLocation,指向spring-mvc的路径(默认在WEB-INF/和servlet-Name一样)
c)配置servlet-mapping(可以仅处理*.do请求)
<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
4)web.xml配置请求和应答字符编码处理器(配置过滤器)
CharacterEncodingFilter
<filter>
<description>请求和应答字符编码过滤器</description>
<filter-name>encoding-filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<!--注意这里和下面配置一致-->
<servlet-name>spring-mvc</servlet-name>
</filter-mapping>
5)配置404,50X,欢迎等特殊页面(忽略)
6)编写测试案例
三.集成spring
1)添加spring依赖
其实没有,因为添加spring-mvc时,已经把spring的核心添加了
2)编写配置文件spring-context.xml(applicationContext.xml)
配置注解事务管理
扫描业务层组件(配置上下文扫描)
3)在web.xml中配置ContextLoaderListener监听器,启用Spring容器
配置ContextConfigLocation,指定spring-context.xml路径
在web.xml配置监听器(在filter和servlet中间)
<listener>
<descripting>启动spring容器</descripting>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-context.xml</param-value>
</context-param>
四.集成c3p0
1)添加依赖
c3p0,jdbc-mysql
2)在spring-context中定义c3p0数据源 CombopooledDaraSource
配置属性
基础信息
driverClass/jdbcurl/user/password
链接数相关
initialPoolSize/minPoolSize/maxPoolSize/acquireIncrement
其他属性请参见相关文档
maven初始搭建一个基础项目(spring mvc+spring+jdbc mysql+jstl)的更多相关文章
- freemarker + spring mvc + spring + mybatis + mysql + maven项目搭建
今天说说搭建项目,使用freemarker + spring mvc + spring + mybatis + mysql + maven搭建web项目. 先假设您已经配置好eclipse的maven ...
- 使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(一)
前言:原来一直使用MyEclipse,换工作后,新公司使用IDEA,初识IDEA发现,哇,它的快捷键可真多啊,但是一路用下来,觉得非常的好用,特别是利用Maven管理,那简直叫一个爽.当然笔者在使用过 ...
- 使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(二)
前言:在使用IntelliJ IDEA和Maven管理搭建Web开发环境(以Spring MVC为例)(一)中已经介绍了如何对web基础环境进行搭建,这里主要演示,如何对spring环境进行搭建,然后 ...
- Spring MVC+Spring+Mybatis+MySQL(IDEA)入门框架搭建
目录 Spring MVC+Spring+Mybatis+MySQL(IDEA)入门框架搭建 0.项目准备 1.数据持久层Mybatis+MySQL 1.1 MySQL数据准备 1.2 Mybatis ...
- 从零开始搭建一个react项目
Nav logo 120 发现 关注 消息 4 搜索 从零开始搭建一个react项目 96 瘦人假噜噜 2017.04.23 23:29* 字数 6330 阅读 32892评论 31喜欢 36 项目地 ...
- Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码)
Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码) 备注: 之前在Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合中 ...
- Spring MVC + Spring + Mybitis开发Java Web程序基础
Spring MVC + Spring + Mybitis是除了SSH外的另外一种常见的web框架组合. Java web开发和普通的Java应用程序开发是不太一样的,下面是一个Java web开发在 ...
- 基于 Express 搭建一个node项目 - 起步
一,如何基于 Express 搭建一个node项目 什么是Express 借用官方的介绍,Express是一个基于Node.js平台的极简.灵活的web应用开发框架,它提供了一系列强大的特性,帮助你创 ...
- 从零搭建一个SpringCloud项目之Feign搭建
从零搭建一个SpringCloud项目之Feign搭建 工程简述 目的:实现trade服务通过feign调用user服务的功能.因为trade服务会用到user里的一些类和接口,所以抽出了其他服务需要 ...
随机推荐
- 纯HTML+CSS写出一颗会飘动的树,有没有惊艳到你呢?
前言 使用HTML+CSS能写出什么惊人的效果呢? 针对这个问题,我总会看到类似的回答,比如没有JS,前端永远都是静态的:HTML5要搭配JS,要不然一文不值. JS固然强大,但CSS也并非一文不值, ...
- 计蒜客 28206.Runway Planning (BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 F)
F. Runway Planning 传送门 题意简直就是有毒,中间bb一堆都是没用的,主要的意思就是度数大于180度的就先减去180度,然后除以10,四舍五入的值就是答案.如果最后结果是0就输出18 ...
- Educational Codeforces Round 33 (Rated for Div. 2) D. Credit Card
D. Credit Card time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Python的功能模块[0] -> wmi -> 获取 Windows 内部信息
wmi模块 / wmi Module WMI (Windows Management Instrumentation) 模块可用于获取 Windows 内部信息.该模块需要 win32com 的支持, ...
- [Python Cookbook] Pandas: 3 Ways to define a DataFrame
Using Series (Row-Wise) import pandas as pd purchase_1 = pd.Series({'Name': 'Chris', 'Item Purchased ...
- Jmeter进行webSocket接口测试
一.运行Jmeter (1) 去官方网站下载jmeter(版本为3.3)并解压.点击bin/jmeter.bat启动jmeter (2) 新建线程组. (3) 在线程组中新建WebSocket Sa ...
- 队列 LinkedBlockingQueue
1 api java.util.concurrent包下的新类.LinkedBlockingQueue就是其中之一,是一个阻塞的线程安全的队列,底层采用链表实现. Li ...
- MySQL 5.7.17 Group Replication 初始
http://blog.csdn.net/mchdba/article/details/53957248
- win2008 安装 配置 mysql
安装的是windows Server 2008 R2 操作系统 按照国际管理,安装了数据库 MYSQL 5.0. 一路顺利,可以通过外部连接MYSQL的时候出现了问题,无论如何也连接不上 发 ...
- JsonArray对象
直接上代码: private static JSONObject createJSONObject() { JSONObject jsonObject = new JSONObject(); json ...