eclipse JavaEE spring,spring mvc,mybits-SSM老年人搭建记录
老求了,好多东西记不住了,再不记以后怕是记不住了。
eclipse JAVAEE for web Version: Mars.2 Release (4.5.2)
tomcat 7.0.29
spring3.1.1
freemarker-2.3.22
commons-io-2.5.jar 没这个东西 request.getParameter() 会报错
算了 来个JAR包截图

源码结构截图

新建tomcat server服务器
打开server管理面板,拖到左边去
window-show view -servers

servers面板空白处右键
new - server

选7.0 再取个酷炫的名字

直接finish完成 就可以在servers面板中看到了

双击myserver打开这个服务的配置
主要说下 server locations 这里的配置,相信很多新手对于这三个鬼是
一脸蒙蔽的,多半会进行鬼畜设置,然后各种报错....

先说 use custom location 如果你选择了这项 并像下面配置

你会发现..你的webapps目录下有个transfeServer 目录和跟tomacat根目录下一样的conf目录
如果你这样设定。。那么当你的tomcat运行的时候 读取是这里的server.xml 和web.xml..
tomcat根目录下conf目录的设置就没效了。。
(transfeServer是我自己取的名字)
所以各位果断选择第二个 use tomcat installation
deploy path 设置 webapps,因为需要将项目发布到tomcat 的webapps下
两个重点
当你建好server时,工作空间(eclipse workspace) 中会多出 servers/Myserver-config(我建TOMCAT server名)的目录,里面的目录和tomcat的conf目录内容一样的
什么意思呢?
就是说当RUN或者DEBUG的时候这里的配置文件会作为基准文件自动拿去覆盖
tomcat下的conf目录下的所有文件。
那么以后就在此改配置就可以了

另外一个重点
选择 use tomcat installation 后,eclipse工作空间基准配置文件servers/Myserver-config/server.xml中的 <host> 标签里面会自动多出一个虚拟目录的设置,果断删掉。。别问为什么。。
一般会在下图的位置出现

以上内容配置好后可以着手 Spring Mvc的配置
先配置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" xmlns:web="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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>transferServer</display-name> <!-- 容器上下文配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/*.xml
</param-value>
</context-param> <!-- 加载Spring容器配置 -->
<!--Spring 上下文监听器 - -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener> --> <!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener> <!-- SPRINGMVC拦截器 -->
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet/*.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <!-- 使用SPRINGMVC拦截器 -->
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <!-- 字符编码配置 -->
<filter>
<filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!--
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/applicationContext.xml</param-value>
</context-param>
--> <!-- 激活Tomcat的defaultServlet来处理静态文件 -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping> </web-app>
分解下web.xml中的配置
context-param 关于这个参数解释可以看这http://www.cnblogs.com/cfas/p/7851899.html
所有与Spring容器对象相关的配置都放到WEB-INF/spring/目录下
如果没有定义具体的xxx.xml 则默认会先找 applicationContext.xml 这个配置
所以WEB-INF/spring/ 需要有 applicationContext.xml 这里到底定义什么我们待会儿再说
接着配置spring 监听器 两个都要

=========================偷懒分割线===========================
还是觉的没必要解释XML的配置了。直接上XML内容吧
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" xmlns:web="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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>transferServer</display-name> <!-- 容器上下文配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/*.xml
</param-value>
</context-param> <!-- 加载Spring容器配置 -->
<!--Spring 上下文监听器 - -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener> <!-- spring 需要log4日志 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param> <!-- 定义LOG4J监听器 -->
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener> <!-- SPRINGMVC拦截器 -->
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet/*.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <!-- 使用SPRINGMVC拦截器 -->
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <!-- 字符编码配置 -->
<filter>
<filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 激活Tomcat的defaultServlet来处理静态文件 -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping> </web-app>
servlet/springMcvServlet.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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <!-- 对所有类进行扫描,以完成Bean创建和自动依赖注入的功能(除去带@Service注解的类) -->
<context:component-scan base-package="com.cn.xql.controller">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan> <!-- don't handle the static resource -->
<mvc:default-servlet-handler /> <!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven /> <!-- 拦截器 -->
<!--<mvc:interceptors> -->
<!-- 多个拦截器,顺序执行 -->
<!-- 登录认证拦截器 -->
<!-- <mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.cn.xql.Handle"/>
</mvc:interceptor>
</mvc:interceptors> -->
<!-- 对所有类进行扫描,以完成Bean创建和自动依赖注入的功能(除去带@Service注解的类) --> <!--通用视图解析器-->
<bean id="viewResolverCommon" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/jsp/"/>
<property name="suffix" value=".jsp"/><!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->
<property name="viewClass">
<value>org.springframework.web.servlet.view.InternalResourceView</value>
</property>
<property name="order" value="2"/>
</bean> <bean id="viewResolverFreemarker" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="order" value="1"></property>
<property name="suffix" value=".html"></property>
<property name="contentType" value="text/html;charset=utf-8"></property>
<property name="viewClass">
<value>org.springframework.web.servlet.view.freemarker.FreeMarkerView</value>
</property>
</bean>
<!--freemarker配置 -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath">
<value>/WEB-INF/tpl/</value>
</property>
<property name="freemarkerSettings"><!-- 设置FreeMarker环境属性 -->
<props>
<prop key="template_update_delay">5</prop><!--刷新模板的周期,单位为秒 -->
<prop key="default_encoding">UTF-8</prop><!--模板的编码格式 -->
<prop key="locale">UTF-8</prop><!--本地化设置 -->
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="time_format">HH:mm:ss</prop>
<prop key="number_format">0.####</prop>
<prop key="boolean_format">true,false</prop>
<prop key="whitespace_stripping">true</prop>
<prop key="tag_syntax">auto_detect</prop>
<prop key="url_escaping_charset">UTF-8</prop>
</props>
</property>
</bean> <!-- 协商视图配置 spring4 才有这个功能
这里用到了 ContentNegotiatingViewResolver ,“内容协商视图解析器”,
其实就是根据返回什么类型的视图,就协商使用哪种视图解析器。
如果返回jsp就使用InternalResourceViewResolver视图解析器,
如果返回JSON格式就使用MappingJackson2JsonView来处理。
如此而已。在 <property name="viewResolvers"> 下的<list> 标签下,
还可以加入其他的各种视图解析器的配置。--> </beans>
spring/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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 支持@Autowired注解导入 -->
<context:annotation-config />
<!-- 测试模型 -->
<bean id="User" class="com.cn.xql.data.domain.User"></bean>
</beans>
下面 这个是 mybits用的
spring/applicationContext-dao.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- JDBC配置参数 -->
<context:property-placeholder location="classpath:jdbc.properties" order="1" ignore-unresolvable="true"/>
<!-- 认证 支持注释的事务声明 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource1"/>
<!-- 数据链接 -->
<bean id="dataSource1" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driver.class0}" />
<property name="jdbcUrl" value="${jdbc.url0}" />
<property name="username" value="${jdbc.username0}"/>
<property name="password" value="${jdbc.password0}"/>
<property name="idleConnectionTestPeriod" value="60"/>
<property name="idleMaxAge" value="240"/>
<property name="maxConnectionsPerPartition" value="30"/>
<property name="minConnectionsPerPartition" value="10"/>
<property name="partitionCount" value="3"/>
<property name="acquireIncrement" value="5"/>
<property name="statementsCacheSize" value="100"/>
<property name="releaseHelperThreads" value="3"/>
</bean>
<!-- 数据源 -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource1" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
<property name="mapperLocations" value="classpath*:com/cn/xql/data/dao/*.xml" />
</bean>
<!-- 数据 自动生成部分-->
<!-- 用户操作日志 -->
<bean id="UserOperationLogMapperImpl" class="com.cn.xql.data.dao.impl.UserOperationLogMapperImpl" p:sqlSessionFactory-ref="sqlSessionFactoryBean"/>
</beans>
注意的问题
本次配置spring 和mybaits 都用的是3.1.1
但是为了使用mybaits 的简单日志功能 ,启用了logImpl...但是..mybaits3.1.1这个设置是没用的,
只有3.2.2才行,所以 最后配置成spring 3.1.1 mybatis3.2.3
这样配置后,运行项目时,启动会有点点延迟。。
这是mybatis-config.xml

eclipse JavaEE spring,spring mvc,mybits-SSM老年人搭建记录的更多相关文章
- maven/eclipse搭建ssm(spring+spring mvc+mybatis)
maven/eclipse搭建ssm(spring+spring mvc+mybatis) 前言 本文旨在利用maven搭建ssm环境,而关于maven的具体内容,大家可以去阅读<Maven 实 ...
- Spring MVC 学习总结(十)——Spring+Spring MVC+MyBatis框架集成(IntelliJ IDEA SSM集成)
与SSH(Struts/Spring/Hibernate/)一样,Spring+SpringMVC+MyBatis也有一个简称SSM,Spring实现业务对象管理,Spring MVC负责请求的转发和 ...
- SSM(Spring+Spring MVC+Mybatis)开发前台后功能完整的java开源博客管理系统
项目描述 本项目通过SSM(SpringMVC+Mybatis+Spring)框架编写的一个人博客管理系统,使用hexo主题,以及MAVEN进行对项目管理,并且前端具有粒子和点击爱心效果.后端的页面框 ...
- ssm整合说明与模板-Spring Spring MVC Mybatis整合开发
ssm整合说明 spring+spring mvc+mybatis 说明 源码下载 由于之前存在ssh框架,spring+struts+hibernate,其中spring负责aop与ioc,所以一般 ...
- 最详细的SSM(Spring+Spring MVC+MyBatis)项目搭建
速览 使用Spring+Spring MVC+MyBatis搭建项目 开发工具IDEA(Ecplise步骤类似,代码完全一样) 项目类型Maven工程 数据库MySQL8.0 数据库连接池:Druid ...
- spring 3 mvc hello world + mavern +jetty
Spring 3 MVC hello world example By mkyong | August 2, 2011 | Updated : June 15, 2015 In this tutori ...
- Gradle – Spring 4 MVC Hello World Example
In this tutorial, we will show you a Gradle + Spring 4 MVC, Hello World Example (JSP view), XML conf ...
- Spring+Spring MVC+MyBatis
Spring+Spring MVC+MyBatis 目录 一.新建一个基于Maven的Web项目 二.创建数据库与表 三.添加依赖包 四.新建POJO实体层 五.新建MyBatis SQL映射层 六. ...
- Spring 4 MVC example with Maven
In this tutorial, we show you a Spring 4 MVC example, using Maven build tool. Technologies used : Sp ...
随机推荐
- 一些网站后台模板源码分析 Particleground.js 验证码
转: https://blog.csdn.net/bcbobo21cn/article/details/51271750 1 灰色简洁企业后台管理模板 效果: 看下项目结构: 它使用了moderniz ...
- 0912 for循环及内置方法
目录 for 循环 1.循环 2.循环取值 3.range 4.for + break 5.for+continue 6.for + else 数字类型内置方法 整型 浮点型 字符串 1.作用 2.作 ...
- oracle ORA-16038 ORA-00257
出现 ORA-16038时也可以参考下边的错误,好像有关联影响 出现ORA-00257错误(空间不足错误),通过查找资料,绝大部分说这是由于归档日志太多,占用了全部的硬盘剩余空间导致的,通过简单删除日 ...
- 数字签名 转载:http://www.youdzone.com/signature.html
What is a Digital Signature?An introduction to Digital Signatures, by David Youd Bob (Bob's public k ...
- qs.stringify()与JSON.stringify()区别
qs.stringify.JSON.stringify虽然都是序列化,但他俩却不是一个东西. qs是nodejs的一个模块 JSON.stringify是js自带的方法,是将json对象转换为json ...
- C# 通过Process.Start() 打开程序 置顶方法
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { try { foreach ...
- Codeforces Round #588 (Div. 2) A. Dawid and Bags of Candies
链接: https://codeforces.com/contest/1230/problem/A 题意: Dawid has four bags of candies. The i-th of th ...
- macOS上更顺手的终端
安装iTerm2.下载地址 https://iterm2.com/downloads/stable/latest 安装Nerd Fonts.下载地址 https://github.com/ryanoa ...
- python--批量修改文件夹名
python代码如下: import os , re import os.path rootdir = r'C:\Users\Administrator\Desktop\222' # rootdir ...
- cookies ,session,localstorage讲解
一 .cookie (1)简介 因为HTTP协议是无状态的,服务器不知道用户上一次做了什么,这严重阻碍了交互式Web应用程序的实现.在典型的网上购物场景中,用户浏览了几个页面,买了一盒饼干和两饮料.最 ...