老求了,好多东西记不住了,再不记以后怕是记不住了。

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老年人搭建记录的更多相关文章

  1. maven/eclipse搭建ssm(spring+spring mvc+mybatis)

    maven/eclipse搭建ssm(spring+spring mvc+mybatis) 前言 本文旨在利用maven搭建ssm环境,而关于maven的具体内容,大家可以去阅读<Maven 实 ...

  2. Spring MVC 学习总结(十)——Spring+Spring MVC+MyBatis框架集成(IntelliJ IDEA SSM集成)

    与SSH(Struts/Spring/Hibernate/)一样,Spring+SpringMVC+MyBatis也有一个简称SSM,Spring实现业务对象管理,Spring MVC负责请求的转发和 ...

  3. SSM(Spring+Spring MVC+Mybatis)开发前台后功能完整的java开源博客管理系统

    项目描述 本项目通过SSM(SpringMVC+Mybatis+Spring)框架编写的一个人博客管理系统,使用hexo主题,以及MAVEN进行对项目管理,并且前端具有粒子和点击爱心效果.后端的页面框 ...

  4. ssm整合说明与模板-Spring Spring MVC Mybatis整合开发

    ssm整合说明 spring+spring mvc+mybatis 说明 源码下载 由于之前存在ssh框架,spring+struts+hibernate,其中spring负责aop与ioc,所以一般 ...

  5. 最详细的SSM(Spring+Spring MVC+MyBatis)项目搭建

    速览 使用Spring+Spring MVC+MyBatis搭建项目 开发工具IDEA(Ecplise步骤类似,代码完全一样) 项目类型Maven工程 数据库MySQL8.0 数据库连接池:Druid ...

  6. 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 ...

  7. 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 ...

  8. Spring+Spring MVC+MyBatis

    Spring+Spring MVC+MyBatis 目录 一.新建一个基于Maven的Web项目 二.创建数据库与表 三.添加依赖包 四.新建POJO实体层 五.新建MyBatis SQL映射层 六. ...

  9. Spring 4 MVC example with Maven

    In this tutorial, we show you a Spring 4 MVC example, using Maven build tool. Technologies used : Sp ...

随机推荐

  1. Oracle数据库结构

    之前写了一篇文章<Oracle-知识结构漫谈> 粗略的介绍了Oracle数据库接口,在这里再更加详细的描述一下,当做是对原有知识的巩固,温故知新. Oracle体系结构数据库的体系结构是从 ...

  2. okhttp任务调度核心类dispatcher解析

    在之前已经对okhttp的同步和异步请求的流程进行了详细的分析,其中任务调度是由dispatcher来实现的,非常重要,所以这次专门来对它进行一个了解,带着问题去进行探究: Q1:okhttp如何实现 ...

  3. django国际化的简单设置

    设置国际化的具体步骤: 一.国际化 1)效果:针对不同的国家的人可以配置不同的语言(一般是英文和中文,  English  Chinese) 2)目的:增加项目的用户量 3)难度:不难 比较费劲的就是 ...

  4. python豆知识: for和while的else语句。

    for语句,当可迭代对象耗尽后执行else语句. while循环,当条件为False后执行else. a = 1 while a != 10: a += 1 else: print(a)

  5. [NOI2008]假面舞会——数论+dfs找环

    原题戳这里 思路 分三种情况讨论: 1.有环 那显然是对于环长取个\(gcd\) 2.有类环 也就是这种情况 1→2→3→4→5→6→7,1→8→9→7 假设第一条链的长度为\(l_1\),第二条为\ ...

  6. C# 反射 (15)

    本章要点 自定义特性 反射 自定义特性运行把自定义元数据与程序元素关联起来.这些元数据时再编译过程中创建的并嵌入到程序集中. 反射是计算机术语,它描述在运行过程中检查和处理程序元素的功能. 反射允许完 ...

  7. 关于maven依赖死活都下载不了终极解决方案

    项目想下载一个依赖,在idea中死都下不了,查看网上各种解决方案都没有效果,出绝招,我使用命令下载jar然后导入到项目引用的maven仓库 类似这种命令:mvn install:install-fil ...

  8. flutter TextField 输入框被软键盘挡住的解决方案

    以前搞ionic1~4的开发中 和react-native   flutter中的机制完全不同, 在flutter 中 当前页面如果存在元素被软键盘挡住 的情况 页面元素的最外层肯定得嵌套一层   S ...

  9. Nginx 配置访问静态资源

    做个简单的配置: 以txt/png/mp4结尾的请求都会按照如下规则寻找返回文件 关键词: location.root location ~ \.(mp4|png|txt) { root /usr/l ...

  10. Spring Framwork Maven dependency

    Spring Framwork 更新时间 2019.12.21 统一版本号 <properties> <!-- spring版本号 --> <spring.version ...