1.新建maven工程

a)  打开eclipse,file->new->project->Maven->Maven Project

springmvc环境搭建以及常见问题解决

 b)  下一步

springmvc环境搭建以及常见问题解决

c)   选择创建的工程为webapp,下一步

springmvc环境搭建以及常见问题解决

 d)   填写项目的group id和artifact id。一般情况下,group id写域名的倒序,artifact id写项目名称即可。最后点完成。

springmvc环境搭建以及常见问题解决

e)   最初建好后,项目目录结构如下

springmvc环境搭建以及常见问题解决

f)   一般的项目目录中,还有src/main/java,src/main/test/java,src/main/test/resources这 三个source folder,需要手动创建。

 

2. 修改项目基本设置

a)    右键此项目名称->Properties->Java Build path,点击source标签。

 springmvc环境搭建以及常见问题解决

 b)  将上missing的文件夹删除,然后重新添加,如下:

springmvc环境搭建以及常见问题解决

 c)   重新添加之后的效果如下:

springmvc环境搭建以及常见问题解决

d)   如果某些folder不想 build path,直接remove就行了(本人只选择了src/main/java, 和 src/main/resources),最终如下:

springmvc环境搭建以及常见问题解决

 e)  修改jre系统

springmvc环境搭建以及常见问题解决

 

springmvc环境搭建以及常见问题解决

 f)  修改java compiler compliance level 与 jre系统的level一致

springmvc环境搭建以及常见问题解决

 g) 修改Project Facets

springmvc环境搭建以及常见问题解决

Dynamic Web Module无法在这里直接修改为3.0,需要打开工程目录下有一个.settings文件夹,打开org.eclipse.wst.common.project.facet.core.xml,做如下修改:

<installed facet="jst.web" version="3.0"/>

重启eclipe就可以看到更改生效了。

3.必要的配置文件

 在Java Resources/scr/main/resources目录下,创建configs文件夹,以便存放在web.xml中声明的配置路径

springmvc环境搭建以及常见问题解决

applicationContext.xml (Spring的公共配置文件)

<?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:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:cache="http://www.springframework.org/schema/cache" xmlns:repo="http://www.springframework.org/schema/data/repository"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd "
    default-lazy-init="true">

    <description>Spring公共配置</description>

    <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
    <context:component-scan base-package="com.ds">
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
        <context:exclude-filter type="annotation"
            expression="org.springframework.web.bind.annotation.ControllerAdvice" />
    </context:component-scan>

</beans>
View Code

相关文章: