Spring日记_02之搭建一个新项目
程序
表现层 业务层 持久层
从持久层开始写
总结如何搭建一个项目
1、新建一个Maven项目
2、可能新建之后会有错,右键Deployment
Descriptor: note, 选择Generate
Deployment Descriptor Stub
3、使用maven仓库导包
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>3.2.8.RELEASE</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.5</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.5</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.5</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.8.RELEASE</version>
</dependency> <dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.0</version>
</dependency> <dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency> <dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency> </dependencies>
dependencies
3.1、查看一下下载的包
如果maven的包迟迟不下载,就右键项目,选择maven – UpdateProject
4、 为项目指定tomcat运行环境
右键项目 – Properties – Targeted Runtimes
5.在下面server的tomcat服务器中添加项目
6 、在src/main/resources下添加两个文件夹
7 、 Spring配置文件
先将原项目的两个配置文件 spring-service.xml和 spring-mybatis.xml 复制过来
将spring-service.xml 改名为spring-web.xml,因为这样更合适一点
spring-mybatis.xml注意改一下文件里的包名,其他的关于mybatis的不用改
spring-web.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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> <!-- 启动注解版本的Spring MVC -->
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="cn.edu.sdu.wh.controller"> </context:component-scan> </beans>
spring-web.xml
spring-mybatis.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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> <!-- 配置dbcp连接池:连接到数据库 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<!-- 连接池的基本连接参数 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/cloud_note"></property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
<!-- 连接池可选参数 -->
<property name="maxActive" value="50"></property>
<property name="initialSize" value="5"></property>
<property name="maxIdle" value="5"></property>
</bean> <!-- 配置MyBatis的 Session 工厂 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 声明MyBatis SQL 声明文件保存的地方 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
</bean> <!-- 配置MyBatis的自动接口扫描 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 数据访问接口的存储位置 -->
<property name="basePackage" value="cn.edu.sdu.wh.dao"></property>
</bean>
</beans>
spring-mybatis.xml
8 、 相应的在src/main/java下添加两个包
9 、 新建一个Servlet
可以查看src/main/webapp/WEB-INF下的web.xml,验证一下
10 、 将Tomcat 发布 然后 运行!
Spring日记_02之搭建一个新项目的更多相关文章
- IDEA搭建一个SpringBoot项目——十分详细(web+mysql)
前排提示: IDEA版本:IntelliJ IDEA 2021.1.1 专业版(是否为专业版影响不大) 搭建目的:前端web页面能够获取到MySQL数据库中的数据 详细步骤: 1. 创建一个新项目 ...
- 从零开始搭建一个react项目
Nav logo 120 发现 关注 消息 4 搜索 从零开始搭建一个react项目 96 瘦人假噜噜 2017.04.23 23:29* 字数 6330 阅读 32892评论 31喜欢 36 项目地 ...
- 从零搭建一个SpringCloud项目之Feign搭建
从零搭建一个SpringCloud项目之Feign搭建 工程简述 目的:实现trade服务通过feign调用user服务的功能.因为trade服务会用到user里的一些类和接口,所以抽出了其他服务需要 ...
- 如何向Openstack社区提交一个新项目
前几天有个朋友问我:自己有一个idea不错的项目,也把基本的框架写好了,想贡献到Openstack社区,却不知道应该怎么做.正好之前我有过类似的经历,那么来分享一下我是如何向Openstack社区提交 ...
- vue-用Vue-cli从零开始搭建一个Vue项目
Vue是近两年来比较火的一个前端框架(渐进式框架吧). Vue两大核心思想:组件化和数据驱动.组件化就是将一个整体合理拆分为一个一个小块(组件),组件可重复使用:数据驱动是前端的未来发展方向,释放了对 ...
- Vue Create 创建一个新项目 命令行创建和视图创建
Vue Create 创建一个新项目 命令行创建和视图创建 开始之前 你可以先 >>:cd desktop[将安装目录切换到桌面] >>:vue -V :Vue CLI 3.0 ...
- 基于 Express 搭建一个node项目 - 起步
一,如何基于 Express 搭建一个node项目 什么是Express 借用官方的介绍,Express是一个基于Node.js平台的极简.灵活的web应用开发框架,它提供了一系列强大的特性,帮助你创 ...
- 将本地的一个新项目上传到GitHub上新建的仓库中去
转载: 如何将本地的一个新项目上传到GitHub上新建的仓库中去 踩过的坑: 1.在git push时报错 error: RPC failed; curl 56 SSL read: error:000 ...
- Google C++测试框架系列入门篇:第二章 开始一个新项目
上一篇:Google C++测试框架系列入门篇:第一章 介绍:为什么使用GTest? 原始链接:Setting up a New Test Project 词汇表 版本号:v_0.1 开始一个新项目 ...
随机推荐
- javascript移动端禁止页面滑动的解决方案
1 前言 移动端网页,发现ios平台的iphone或者ipad,网页可以上下左右移动,而Android版则不会.仅作为记录使用. 2 代码 var mo=function(e){e.preventDe ...
- sudo初级授权设置
linux中,不可能人人都是用root用户去修改一些文件或者操作,所以一般需要用到对用户的权限控制,linux中可以是sudo来实现 首先,权限控制的文件中 /etc/sudoers中进行配置,文件为 ...
- Swift 学习- 01 -- 基础部分
print("世界,你好") var myVariable = 42 myVariable = 50 let myConstant = 42 let implicitinteger ...
- Confluence 6 任务的类型
下面是有关你可以调整的计划任务列表. Confluence 备份(Back Up Confluence) 对 Confluence 站点执行备份操作. 每集群(Per cluster) At 2am ...
- Confluence 6 数据库表-杂项(Miscellaneous)
这些部分是一些其他的表格,这些表格有必要在这里提及下能帮你更好的了解系统. os_propertyentry 有关实体和属性相关的特性. bandana 所有的持久层.这个表格包含的的内容有用户设置和 ...
- Confluence 6 导入模板的备注
创建你自己的模板组件(template bundles).你可以使用插件(add-on,也可以被称 plugin)来创建模板组件然后将这些模板组件上传到你的 Confluence 站点中.你可以从你的 ...
- error: js/dist/app.js from UglifyJs Unexpected token: name (Dom7)
What you did I have installed Swiper as normal dependency in my Project and import it to my scripts ...
- AI-响应式、分页器
响应式 如果在setting配置下列,当只有BrowsableAPIRenderer时,只会返回浏览器页面:当配置成JSONRenderer,会返回json数据 REST_FRAMEWORK={ 'D ...
- 常见的爬虫分析库(4)-爬虫之PyQuery
PyQuery 是 Python 仿照 jQuery 的严格实现.语法与 jQuery 几乎完全相同. 官方文档:http://pyquery.readthedocs.io/ 安装 1 pip ins ...
- windows server 2012 R2 远程桌面授权模式尚未配置
windows server 2012 R2 远程桌面授权模式尚未配置,远程桌面服务将在120天内停止工作.如何破解这个宽限期,目前企业7位协议号码均不包含2012 R2以上授权. 那么只能蛋疼的“破 ...