Springboot & Mybatis 构建restful 服务二
Springboot & Mybatis 构建restful 服务二
1 前置条件
成功执行完Springboot & Mybatis 构建restful 服务一
2 restful service 打包问题
要求打包成以下格式:
---tar
---jar Service的源代码和 Pom.xml
---lib Service的依赖jar包
---config Service的配置文件
3 配置文件外置
1)修改 application.properties 文件
src/main/resources/application.properties
#新增
#配置Oracle数据库的驱动类
spring.datasource.driverClass=oracle.jdbc.driver.OracleDriver
#配置本地类路径的入口
spring.classPathEntry.location=classpath:lib/ojdbc6-1.0.1.jar
2)修改generatorConfig.xml:
<!-- 修改classPathEntry里 location和jdbcConnection的数据库连接,设置从资源文件中读取值 -->
<classPathEntry location="${spring.classPathEntry.location}" />
<jdbcConnection driverClass="${spring.datasource.driverClass}"
connectionURL="${spring.datasource.url}"
userId="${spring.datasource.username}" password="${spring.datasource.password}">
</jdbcConnection>
3)修改 POM:
在build 里新增以下代码:用于打包时只打包后缀名为 .java的文件,忽略配置文件(src/main/resources)。并将该目录下所有的文件复制到${project.build.directory}/config
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.*</include>
</includes>
<filtering>true</filtering>
<targetPath>${project.build.directory}/config</targetPath>
</resource>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
添加maven-jar-plugin插件,指定主类和依赖 jar 所在位置
(此例中为:main/java/com/serena)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.serena.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
添加maven-dependency-plugin插件,将所有依赖 jar 复制到${project.build.directory}/lib目录
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
添加maven-antrun-plugin插件,用于将生成的可运行的 jar ,配置文件,依赖 jar,启动脚本等打包成tar压缩包
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}/config" />
<mkdir dir="${project.build.directory}/lib" />
<mkdir dir="${project.build.directory}/bin" />
<mkdir dir="${project.build.directory}/log" />
<tar tarfile="${project.build.directory}/${project.build.finalName}.tar"
basedir="${project.build.directory}" includes="*.xml,config/*,log,bin,bin/*,lib/*,startup.sh,shutdown.sh,${project.build.finalName}.jar" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
4.在终端输入如下测试指令
#cd 项目所在目录
cd /Users/psj/Documents/pro/xm/AccountBalance
mvn clean package
cd target
#将 tar 包复制到自己指定目录(/Users/psj/Desktop/t/)
cp AccountBalance-0.0.1-SNAPSHOT.tar /Users/psj/Desktop/t/
#cd 到上个操作指定的目录
cd /Users/psj/Desktop/t
#解压 tar 包
tar -xvf AccountBalance-0.0.1-SNAPSHOT.tar
#此时可查看目录结构如要求所示
ll
#运行 可执行jar,测试结果
java -jar AccountBalance-0.0.1-SNAPSHOT.jar
#
#打开新的iterm 窗口(command+n)
http localhost:8101/accounts
http localhost:8101/account/U00001
#
#返回上个 iterm 窗口,control+c 结束服务。
Springboot & Mybatis 构建restful 服务二的更多相关文章
- Springboot & Mybatis 构建restful 服务三
Springboot & Mybatis 构建restful 服务三 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务二 2 restful ...
- Springboot & Mybatis 构建restful 服务五
Springboot & Mybatis 构建restful 服务五 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务四 2 restful ...
- Springboot & Mybatis 构建restful 服务四
Springboot & Mybatis 构建restful 服务四 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务三 2 restful ...
- Springboot & Mybatis 构建restful 服务
Springboot & Mybatis 构建restful 服务一 1 前置条件 jdk测试:java -version maven测试:命令行之行mvn -v eclipse及maven插 ...
- 基于SpringBoot开发一个Restful服务,实现增删改查功能
前言 在去年的时候,在各种渠道中略微的了解了SpringBoot,在开发web项目的时候是如何的方便.快捷.但是当时并没有认真的去学习下,毕竟感觉自己在Struts和SpringMVC都用得不太熟练. ...
- jersey+maven构建restful服务
一.新建一个Maven Web项目 a) 新建一个简单的Maven项目 b) 将简单的Maven项目转成Web项目 (若没出现further configuration available--或里面的 ...
- 用Jersey构建RESTful服务7--Jersey+SQLServer+Hibernate4.3+Spring3.2
一.整体说明 本例执行演示了用 Jersey 构建 RESTful 服务中.怎样集成 Spring3 二.环境 1.上文的项目RestDemo 2.Spring及其它相关的jar ,导入项目 三.配置 ...
- JAX-RS(基于Jersey) + Spring 4.x + MyBatis构建REST服务架构
0. 大背景 众所周知,REST架构已经成为现代服务端的趋势. 很多公司,已经采用REST作为App, H5以及其它客户端的服务端架构. 1. 什么是JAX-RS? JAX-RS是JAVA EE6 引 ...
- SpringBoot 快速构建微服务体系 知识点总结
可以通过http://start.spring.io/构建一个SpringBoot的脚手架项目 一.微服务 1.SpringBoot是一个可使用Java构建微服务的微框架. 2.微服务就是要倡导大家尽 ...
随机推荐
- 主成分分析、实例及R语言原理实现
欢迎批评指正! 主成分分析(principal component analysis,PCA) 一.几何的角度理解PCA -- 举例:将原来的三维空间投影到方差最大且线性无关的两个方向(二维空间). ...
- javaScript:压缩图片并上传
html代码: <input id="file" type="file" name="filesName"> js代码: var ...
- python之路:模块初识
python王者开发之路:模块初识 模块初识我现在讲的确有点早.不过没关系,后面我会详细说模块. 模块,也就是库,是python三剑客之一.这三剑客,函数.库和类,都是由程序编写而成的.之所以我先说模 ...
- Laravel 5.3 单用户登录的简单实现
需求 一个用户不能重复登录. 后登录者可以踢掉前者. 设计思路: 核心概念 用户ID: 是用户表主键 singleToken 算法: singleToken = md5(用户IP + 用户ID + 登 ...
- docker swarm集群搭建以及使用滚动更新
基础环境,三台虚拟机 172.17.3.70 172.17.3.71 172.17.3.72 系统配置:centos 7,关闭selinux 需要优化的基础配置: [root@sw1 ~]# vim ...
- 布局inline-block问题
当在一行中需要展示多个拥有块级属性的标签元素时,通常选择display:inline-block; 优点:不用设置浮动或定位,浮动脱离文档流还需要清除浮动,定位降低扩展性. 问题: 1.标签元素之间会 ...
- linux下的dhcp服务器实现
一.得到udhcpd(udhcp服务端): 1.解压busybox 2.配置busybox Networking Utilities——> [*] udhcp server(udhcpd) [* ...
- 云笔记项目-Spring事务学习-传播NOT_SUPPORTED
接下来测试事务传播属性设置为NOT_SUPPORTED Service层 Service层主要设置如下,其中还插入了REQUIRED作为比较. package Service; import java ...
- servlet实现mysql数据库分页
一.分页所需要的sql语句准备 select * from table limit m,n其中m是指记录开始的index,从0开始,表示第一条记录n是指从第m+1条开始,取n条. 例如:select ...
- virtualenv+pyenv管理python工作环境
因为python2与3之间存在差异,所以日常工作中可能需要在2与3之间来回切换.在相同的python版本中,有可能有的项目需要用到django1.8,别的项目需要用到django1.9,所以如果可以在 ...