您的位置:首页 > 编程语言 > Java开发

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

2016-03-14 23:59 507 查看


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.分别创建文件夹,其中,
test
main
平行,在
main
下创建
Java
文件夹,在
test
文件夹下创建
java
文件夹和
resources
文件夹.



7.选中项目,F12,进入项目设置页面。

在该页面中,将
main/java
标识为
Sources
main/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打包

首先配置tomcat或者jetty环境

然后build





3.在tomcat中部署



4.使用maven打包
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: