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

来源:互联网 发布:seo网络营销推广工资 编辑:程序博客网 时间:2024/06/01 15:39

Maven的webapp工程目录

maven web app

IDEA 中的项目截图

项目截图

忽视那个temptest文件夹

使用 Maven创建webapp

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

1

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

2

3.选择maven的相关信息

3

4.项目名称及位置

4

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

5

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

6

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

添加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

spring

app-context

2.添加web配置

同样的操作

web

选中web.xml的路径

path

配置完毕。

maven打包

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

  2. 然后build

build

bulid2

3.在tomcat中部署

tomcat

4.使用maven打包

0 0
原创粉丝点击