IDEA 中的项目截图
忽视那个temptest文件夹
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
在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的路径
配置完毕。
首先配置tomcat或者jetty环境
然后build
3.在tomcat中部署
4.使用maven打包
版权声明:欢迎交流
IDEA & Maven & Spring & MyBatis 编写数据服务
原文地址:http://blog.csdn.net/weiyongxuan/article/details/47442149