码迷,mamicode.com
首页 > 编程语言 > 详细

IDEA & Maven & Spring & MyBatis 编写数据服务

时间:2015-08-12 14:39:21      阅读:340      评论:0      收藏:0      [点我收藏+]

标签:idea   web app   maven   


Maven的webapp工程目录

技术分享

IDEA 中的项目截图

技术分享

忽视那个temptest文件夹

使用 Maven创建webapp

1.创建项目,选择Maven,模板选择 webapp

技术分享

2.填写相关的信息
说明:maven是以 groupId artifactId packaging version来唯一标识一个项目的。
- groupId:用来标识团体,公司,小组,组织,项目,或者其它团体,一般以逆向域名开头。org.apache
- artifactId:项目的唯一标识符,不需要.,比如 tomcat
- packaging: 标识项目的类型,如jar,war等。
- version :版本号

技术分享

3.选择maven的相关信息

技术分享

4.项目名称及位置

技术分享

5.创建完成后的工程目录

技术分享

6.分别创建文件夹,其中,testmain平行,在main下创建java文件夹,在test文件夹下创建java文件夹和resources文件夹.

技术分享

7.选中项目,F12,进入项目设置页面。
在该页面中,将main/java 标识为Sourcesmain/resources标识为Resources,将test/java标识为Tests,将test/resources标识为Test Resources
之前由于test文件夹标识错误,导致扫描不到包,报错找不到bean
技术分享

添加spring及web支持

在pom.xml中添加相关的依赖,在resources文件夹下创建config文件夹,编写application-context.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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 配置 要扫描的包-->
    <mvc:annotation-driven/>
    <context:component-scan base-package="com.fengtang.dataservice"/>
    <!-- 配置其他的配置文件 -->
    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/config/other/db.properties</value>
                <value>classpath:/config/other/dubbo.properties</value>
            </list>
        </property>
    </bean>
    <!-- @Component and @Resource -->
    <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
</beans>

打开(Open Module Setting)页面,选中项目,F12

1.添加spring配置
技术分享

点击+,添加spring,然后,选中application-context.xml

技术分享

技术分享

2.添加web配置

同样的操作

技术分享

选中web.xml的路径

技术分享

配置完毕。

maven打包

  1. 首先配置tomcat或者jetty环境

  2. 然后build

技术分享

技术分享

3.在tomcat中部署

技术分享

4.使用maven打包

版权声明:欢迎交流

IDEA & Maven & Spring & MyBatis 编写数据服务

标签:idea   web app   maven   

原文地址:http://blog.csdn.net/weiyongxuan/article/details/47442149

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!