使用maven快速构建SSM项目
来源:互联网 发布:淘宝 安卓 旧版 编辑:程序博客网 时间:2024/06/10 22:24
这里我就假设大家都已经配置好Maven,就不在重复说明了。若没有配置可以参考《首次使用maven的配置过程》。
1.新建Maven项目
工作区–右键—new—other–搜索maven
现在maven项目新建完毕,需要将其转化为一个动态web项目。
2.将Maven项目转为动态web项目
选中项目—右键–properties—project facets—Dynamic Web Module—(RunTime)Appache Tomcat—…
上面的步骤一般首次都会报如下错误,我们重复刚刚的操作就行
重复步骤如下:注意依然要再次选择Dynamic Web Module ,然后选择 Appache Tomcat,再重复下面的
这样Maven转为Web项目就成功了。现在来配置一下SSM架构了。
3.构建SSM框架
3.1配置pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.java</groupId> <artifactId>Maven_SSM_Demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>Maven_SSM_Demo</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- 声明spring 对应版本:标签名可以任意取 --> <spring-version>4.3.8.RELEASE</spring-version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.8.RELEASE</version> </dependency> <!-- ssm开发 Spring jar / Spring MVCjar SpringJDBC jar --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring-version}</version> </dependency> <!-- mybaits jar --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.1</version> </dependency> <!-- mybatis和Spring集成需要的jar --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.0</version> </dependency> <!--c3p0 jar --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <!-- jackson @ResponseBody --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.7</version> </dependency> <!-- mysql 数据库 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency> </dependencies></project>
3.2配置web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"><display-name>Maven_SSM_Demo</display-name> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>HiddenHttpMethod</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>HiddenHttpMethod</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list></web-app>
3.3有关Maven与Web基础的配置
选中项目—右键—properties—deployment Assembly–add(目的:让maven的jar映射到web的lib下)
最后,apply —ok保存即可
3.4新建Source Folder
在资源夹是专门用来放置配置文件的
3.5 applicationContext.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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- springmvc处理静态资源 --> <mvc:default-servlet-handler /> <mvc:annotation-driven></mvc:annotation-driven> <context:component-scan base-package="com.java"></context:component-scan> <!-- 第一步 加载jdbc.properties --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 第二步,配置C3P0数据连接池 --> <!-- 需要数据源 C3P0 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc_driver}"></property> <property name="jdbcUrl" value="${jdbc_url}"></property> <property name="password" value="${jdbc_password}"></property> <property name="user" value="${jdbc_user}"></property> </bean> <!-- 第三步 SpringJDBC --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- mybatis集成 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <!-- mappers 配置文件映射 --> <property name="mapperLocations" value="classpath:com/java/dao/*.xml"></property> <!-- 别名设置 将该包内所有的类定义了别名,别名就是其类名 --> <property name="typeAliasesPackage" value="com.java.bean"></property> </bean> <!-- 配置对应的SqlSession --> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg> </bean> <!-- 自动扫描,完成代码Mapper --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.java.dao"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean></beans>
3.6 jdbc.properties配置
# remark#driver=oracle.jdbc.driver.OracleDriver#url=jdbc:oracle:thin:@localhost:1521:orcl#user=test1#password=test1#mysql connectionjdbc_driver=com.mysql.jdbc.Driverjdbc_url=jdbc:mysql://localhost:3306/mybatisjdbc_user=rootjdbc_password=123
这样使用Maven构建SSM项目就成功来。可以自己可以测试一下。
我的小demo项目–《Maven_SSM_Demo》,项目做了测试,有相关的sql文件,直接可以直接测试。
阅读全文
0 0
- 使用maven快速构建SSM项目
- intellij idea 使用maven构建SSM项目
- Maven构建SSM项目
- Maven方式构建SSM项目
- JAVA Eclipse使用Maven构建web项目详解(SSM框架)
- 使用maven构建ssm项目的pom文件
- springboot+maven快速构建项目
- springBoot maven快速构建项目
- 快速使用 maven 构建一个 spring web 项目
- 快速使用 maven 构建一个 spring web 项目
- 使用spring boot快速构建spring框架的maven项目
- Maven快速使用教程(二) spring boot 项目构建
- SSM整合---使用Maven依赖管理&构建
- 使用Maven构建项目
- 使用Maven构建项目
- 使用Maven构建项目
- 使用Maven构建项目
- 使用maven构建项目
- 虚拟地址、线性地址和物理地址的转换
- JAVA 缓存一致性协议
- Spring框架的JDBC模板和事务管理
- LeetCode 448. Find All Numbers Disappeared in an Array
- oracle数据一致性和事务控制
- 使用maven快速构建SSM项目
- HBase源码分析之远程调试
- SQL(Oracle)学习20170917
- 40. Combination Sum II
- 页面表格可编辑input框变大的问题
- 推荐一个本书《深入分析Java Web技术内幕(修订版)》,许令波著
- Java中函数回调机制的深入理解
- 子类覆盖父类方法问题
- 有序链表合并