eclipse如何搭建springmvc +mybatis

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了eclipse如何搭建springmvc +mybatis相关的知识,希望对你有一定的参考价值。

SpringMVC+MyBatis+Freemarker 简单框架搭建(一)

一、开发环境:
Eclipse、Tomcat、SVN等请参见如下的帖子,很详细了。
http://www.iteye.com/topic/982182

svn和maven插件的安装:
1、先安装gef插件
地址:http://download.eclipse.org/tools/gef/updates/interim/
2、安装svn插件
地址:http://subclipse.tigris.org/update_1.6.x
3、maven插件
m2eclipse-core Update 地址: http://m2eclipse.sonatype.org/sites/m2e
m2eclipse-extras Update 地市: http://m2eclipse.sonatype.org/sites/m2e-extras
4、安装可能出现的问题
直接在线安装maven2 会出现依赖插件找不到的问题,无法安装。必须先安装gef 插件后才能安 装m2eclipse-core 插件,然而安装m2eclipse-extras 插件又依赖subclipse 插件。所以,三个插 件的正确的安装顺序是:gef插件 》subclipse插件 》m2eclipse插件

二、web.xml 和 applicationContext.xml 配置
1、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/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

<!-- Spring MVC 配置 -->
<servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:contextConfigLocation-springService.xml</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<!-- 事件监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- shiro 权限控制的过滤器 -->

<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

<!-- session超时定义,单位为分钟 -->
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- 设置servlet编码开始 -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
<!-- 设置servlet编码结束 -->

<display-name>Archetype Created Web Application</display-name>
</web-app>

<context-param>节点和<listener>节点是web项目启动时最先读取的两个节点,所以这两个节点里面所配置的内容是web项目启动时最先加载的部分。
<context-param>节点中配置的applicationContext.xml里面主要是数据库的配置信息,以及事务等等
<listener>节点配置的是web请求的监听器

2、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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
">

<!-- 自动注解除Controller以外的Component -->
<context:component-scan base-package="com.weiluo.example">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<!-- 此配置可以让我们以$xxx的形式来读取property.properties里面的信息 -->
<!-- <context:property-placeholder/> -->

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>

<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="$jdbc.driver"></property>
<property name="url"
value="$jdbc.url"></property>
<property name="username" value="$jdbc.username"></property>
<property name="password" value="$jdbc.password"></property>

<!-- Connection Pooling Info -->
<property name="maxActive" value="$dbcp.maxActive" />
<property name="maxIdle" value="$dbcp.maxIdle" />
<property name="defaultAutoCommit" value="false" />
<!-- 连接Idle一个小时后超时 -->
<property name="timeBetweenEvictionRunsMillis" value="360000" />
<property name="minEvictableIdleTimeMillis" value="360000" />
</bean>

<!-- 配置SessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref = "dataSource"
p:configLocation = "classpath:sqlMapConfig.xml" />

<!-- 采用spring与mybatis整合的第二种方法 -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref = "dataSource" />

<!-- MapperScanner配置,自动搜索mapper里面的对象,并注入 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage = "com.weiluo.example.entity" />

<!-- 启动Spring注解事务 -->
<tx:annotation-driven/>

</beans>

3、web.xml中的<servlet>节点配置的是与请求处理相关的一些内容,主要是 url路由处理器,视图解析器,等等,如下:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

<!-- url映射拦截器 -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="1" />
</bean>
<!-- 配置数据格式转换器 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="jsonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
</bean>

<!-- 开启controller注解支持 -->
<!-- 注:如果base-package=cn.javass 则注解事务不起作用 TODO 读源码 -->
<context:component-scan base-package="com.weiluo.example.controller">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 因为web-inf目录下面的静态资源文件是不能直接通过目录过去的,所以需要特殊声明-->
<mvc:resources location="/static/" mapping="/static/**" />

<!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".html" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="exposeRequestAttributes" value="true" />
<property name="exposeSessionAttributes" value="true" />
<property name="requestContextAttribute" value="rc" />
<property name="contentType" value="text/html;charset=GB2312" />
<property name="order" value="0"/>
</bean>

<!-- 自定义的freemarker标签 -->
<bean id="blockDirective"
class="com.weiluo.example.freemarker.directive.BlockDirective" />
<bean id="extendsDirective"
class="com.weiluo.example.freemarker.directive.ExtendsDirective" />
<bean id="overrideDirective"
class="com.weiluo.example.freemarker.directive.OverrideDirective" />
<bean id="superDirective"
class="com.weiluo.example.freemarker.directive.SuperDirective" />

<!-- freemarker的配置项 -->
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/views/" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">5</prop>
<prop key="defaultEncoding">GB2312</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="time_format">HH:mm:ss</prop>
<prop key="number_format">0.######</prop>
<prop key="whitespace_stripping">true</prop>
</props>
</property>
<property name="freemarkerVariables">
<map>
<entry key="extends" value-ref="extendsDirective"></entry>
<entry key="override" value-ref="overrideDirective"></entry>
<entry key="block" value-ref="blockDirective"></entry>
<entry key="super" value-ref="superDirective"></entry>
</map>
</property>
</bean>

</beans>

4、另外,一些常常变化的信息习惯于存放在application.properties文件里面,如:

#oracle version database setting
database=sqlserver
#jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.driver=net.sourceforge.jtds.jdbc.Driver
#jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=SpringMyBatisExample
#jdbc.url=jdbc:mysql://localhost:3306/springmvcdemo
jdbc.username=sa
jdbc.password=sasa

#dbcp settings
dbcp.maxIdle=5
dbcp.maxActive=20

到这里,一个spring mvc的基本框架就已经搭建起来了。
后续再完成数据库mybatis的配置以及freemarker的配置。
参考技术A     eclipse搭建springmvc +mybatis的步骤如下:

    1、首先创建Web项目;

    2、引入所有的相关jar文件;

    3、配置web.xml;

    web.xml是项目的入口,既然使用spring那么当然要添加Spring的支持啦,spring默认加载的是applicationContext.xml,由于需要集成MyBatis,所以把Spring的配置文件强制指定名称,并与MyBatis一起配置,减少配置文件数量。

    (1)、先指定spring配置文件名名称与路径


<!--  Spring 上下文参数 加载Spring配置文件 -->  
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath*:xmlconfig/springmvc-mybatis.xml</param-value>  
    </context-param>

    (2)、再执行Spring上下文监听配置   
<listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
</listener>



    (3)、添加支持Spring mvc 的配置

<!-- spring mvc 拦截器配置 -->  
<servlet>  
    <servlet-name>springmvc</servlet-name>  
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <init-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value>classpath*:/xmlconfig/springmvc-servlet.xml</param-value>  
        </init-param>  
        <load-on-startup>1</load-on-startup>  
    </servlet>  
    <servlet-mapping>  
    <servlet-name>springmvc</servlet-name>  
    <url-pattern>/</url-pattern>  
</servlet-mapping>



    由于采用的是tomcat服务器,为了让静态的资源直接交给tomcat处理,所以在web.xml中配置了以下配置:


<!-- 激活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>



    4、配置springmvc-mybatis.xml和springmvc-servlet.xml;

    springmvc-mybatis.xml:


<?xml version="1.0" encoding="UTF-8"?>  
<beans 配置信息>   
  
    <!-- 数据源定义-->  
    <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource">  
        <property name="driverClass" value="jdbc:mysql://主机加端口号/web" />  
        <property name="jdbcUrl" value="root" />  
        <property name="username" value="123456" />  
        <property name="password" value="com.mysql.jdbc.Driver" />  
    </bean>  
      
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <property name="mapperLocations" value="classpath*:dbmap/*Mapper.xml" />  
    </bean>  
      
    <!-- 配置事务管理器 -->  
    <bean id="transactionManager"   
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource" />  
    </bean>  
      
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">  
        <property name="dataSource">  
            <ref bean="dataSource" />  
        </property>  
    </bean>  
    <bean id="defaultLobHandler"   
          class="org.springframework.jdbc.support.lob.DefaultLobHandler"   
          lazy-init="true"/>  
    <!-- 查 找 类 路 径 下 的 映 射 器 并 自 动 将 它 们 创 建 成 MapperFactoryBean-->  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <property name="basePackage" value="com.ansitech.web.orm.mapper" />  
    </bean>  
</beans>

    spring-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<beans 配置信息>  
      
    <description>Spring MVC Configuration</description>  
      
    <!-- 对静态资源文件的访问,交给default servlet handler处理 -->  
    <mvc:default-servlet-handler/>  
      
    <!-- 启用spring mvc 注解 -->  
    <context:annotation-config />  
      
    <!-- 默认的注解映射的支持 -->  
    <mvc:annotation-driven />  
      
    <!-- 设置使用注解的类所在的jar包 -->  
    <context:component-scan base-package="com.ansitech.web"></context:component-scan>  
      
    <!-- 完成请求和注解POJO的映射 -->  
<bean class=  
      "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>  
      
    <!-- JSP视图文件解析配置 -->  
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>  
    <property name="prefix" value="/WEB-INF/view/"/>  
    <property name="suffix" value=".jsp"/>  
    <property name="viewNames" value="jsp/*"/>  
    <property name="order" value="1"/>  
</bean>  
      
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">  
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>  
    <property name="prefix" value="/WEB-INF/view/"/>  
    <property name="suffix" value=".jsp"/>  
    <property name="order" value="2"/>  
</bean>  
  
    <!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1024(B)=10485760 bytes -->    
    <bean id="multipartResolver"   
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    
        <!-- one of the properties available; the maximum file size in bytes -->  
        <property name="maxUploadSize">  
            <value>5242880</value>  
        </property>  
    </bean>  
</beans>



    web.xml:
<?xml version="1.0" encoding="UTF-8"?>  
<web-app 配置信息>  
    <!-- 程序Session配置 -->  
    <session-config>  
        <!-- Session过期时间(单位:分) -->  
        <session-timeout>30</session-timeout>  
    </session-config>  
      
    <!-- 激活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>  
  
    <!--  Spring 上下文参数 加载Spring配置文件 -->  
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath*:xmlconfig/springmvc-mybatis.xml</param-value>  
    </context-param>  
    
    <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener>  
      
    <!-- spring mvc 拦截器配置 -->  
    <servlet>  
        <servlet-name>springmvc</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <init-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value>classpath*:/xmlconfig/springmvc-servlet.xml</param-value>  
        </init-param>  
        <load-on-startup>1</load-on-startup>  
    </servlet>  
    <servlet-mapping>  
        <servlet-name>springmvc</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>  
  
    <!-- 欢迎页 -->  
    <welcome-file-list>  
        <welcome-file>/index.html</welcome-file>  
    </welcome-file-list>  
</web-app>

    至此,就完成了springmvc +mybatis的搭建了。
参考技术B

一,jar包准备。

下载了Mybatis 和 Spring 的jar包基本上都添加上去了,如图:

二、 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/web-app_2_5.xsd"

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>WeShare</display-name>

<welcome-file-list>

<welcome-file>/jumper.html</welcome-file>

</welcome-file-list>

<!-- 加载spring容器配置 -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!-- 设置Spring容器加载配置文件路径 (主要配置都在这里面) -->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/applicationContext.xml

  </param-value>

</context-param>


<!-- 配置Spring核心控制器 -->

<servlet>

<servlet-name>web</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<!-- 不指定 <init-param> 会自动找web.xml相同路径下 web-servlet.xml文件 -->

<!-- 

<init-param> 

<param-name>contextConfigLocation</param-name> 

<param-value>/WEB-INF/dispatcher.xml</param-value> 

</init-param> 

-->

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>web</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>web</servlet-name>

<url-pattern>*.action</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>

</filter>

<filter-mapping>

<filter-name>characterEncodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

</init-param>

</servlet>

<error-page>

<exception-type>java.lang.Throwable</exception-type>

<location>/common/jsp/error.jsp</location>

</error-page>

<error-page>

<error-code>403</error-code>

<location>/common/jsp/error403.jsp</location>

</error-page>

<error-page>

<error-code>404</error-code>

<location>/common/jsp/error404.jsp</location>

</error-page>

</web-app>

三、 <!-- 配置Spring核心控制器 -->
 <servlet>
  <servlet-name>web</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <!-- 不指定 <init-param> 会自动找web.xml相同路径下 web-servlet.xml文件 -->
  <!-- 
  <init-param> 
   <param-name>contextConfigLocation</param-name> 
   <param-value>/WEB-INF/dispatcher.xml</param-value> 
  </init-param> 
   -->
  <load-on-startup>1</load-on-startup>
 </servlet>  这个我使用的是默认的 web-servlet.xml文件. 如下:

<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:tx="http://www.springframework.org/schema/tx"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:aop="http://www.springframework.org/schema/aop"

       xmlns:p="http://www.springframework.org/schema/p" 

       xsi:schemaLocation="http://www.springframework.org/schema/beans 

       http://www.springframework.org/schema/beans/spring-beans.xsd

       http://www.springframework.org/schema/tx 

       http://www.springframework.org/schema/tx/spring-tx.xsd

       http://www.springframework.org/schema/context 

       http://www.springframework.org/schema/context/spring-context.xsd

       http://www.springframework.org/schema/aop

       http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

    <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >

    <property name="prefix" value="/"></property>

    <property name="suffix" value=".jsp"></property>

    </bean>

    <context:component-scan base-package="com.weshare.**.web"/>

     <!-- /hrtiaoxin/src/java/com/guohualife/   hr/pfc/   web/controller/HrDeptMarkController.java -->

</beans>

以上是关于eclipse如何搭建springmvc +mybatis的主要内容,如果未能解决你的问题,请参考以下文章

Jenkins+Maven+Git搭建持续集成和自动化部署的配置

SpringBoot+ShardingSphereJDBC实现读写分离!

论单元测试之重要性

java 后台框架 支持APP接口调用 APP后台 手机后台框架java springmvc myb

JAVA架构师之SpringBoot,SpringCloud构建微服务项目架构

如何自学编程?