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 服务二的更多相关文章

  1. Springboot & Mybatis 构建restful 服务三

    Springboot & Mybatis 构建restful 服务三 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务二 2 restful ...

  2. Springboot & Mybatis 构建restful 服务五

    Springboot & Mybatis 构建restful 服务五 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务四 2 restful ...

  3. Springboot & Mybatis 构建restful 服务四

    Springboot & Mybatis 构建restful 服务四 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务三 2 restful ...

  4. Springboot & Mybatis 构建restful 服务

    Springboot & Mybatis 构建restful 服务一 1 前置条件 jdk测试:java -version maven测试:命令行之行mvn -v eclipse及maven插 ...

  5. 基于SpringBoot开发一个Restful服务,实现增删改查功能

    前言 在去年的时候,在各种渠道中略微的了解了SpringBoot,在开发web项目的时候是如何的方便.快捷.但是当时并没有认真的去学习下,毕竟感觉自己在Struts和SpringMVC都用得不太熟练. ...

  6. jersey+maven构建restful服务

    一.新建一个Maven Web项目 a) 新建一个简单的Maven项目 b) 将简单的Maven项目转成Web项目 (若没出现further configuration available--或里面的 ...

  7. 用Jersey构建RESTful服务7--Jersey+SQLServer+Hibernate4.3+Spring3.2

    一.整体说明 本例执行演示了用 Jersey 构建 RESTful 服务中.怎样集成 Spring3 二.环境 1.上文的项目RestDemo 2.Spring及其它相关的jar ,导入项目 三.配置 ...

  8. JAX-RS(基于Jersey) + Spring 4.x + MyBatis构建REST服务架构

    0. 大背景 众所周知,REST架构已经成为现代服务端的趋势. 很多公司,已经采用REST作为App, H5以及其它客户端的服务端架构. 1. 什么是JAX-RS? JAX-RS是JAVA EE6 引 ...

  9. SpringBoot 快速构建微服务体系 知识点总结

    可以通过http://start.spring.io/构建一个SpringBoot的脚手架项目 一.微服务 1.SpringBoot是一个可使用Java构建微服务的微框架. 2.微服务就是要倡导大家尽 ...

随机推荐

  1. [C#]打包项目[转]

    原文:https://www.cnblogs.com/danyu/p/7243706.html 加入自定义操作:https://blog.csdn.net/ristal/article/details ...

  2. Unable to connect to MKS;Too many scoket connect attempts;giving up

    Unable to connect to MKS;Too many scoket connect attempts;giving up(无法连接到MKS;太多scoket连接尝试;放弃) 第一次学习虚 ...

  3. ElasticSearch日常使用脚本

    1.启动服务要切换到非root账户 (例子:su - elk --command="/usr/local/elk/kibana/bin/kibana serve &")2. ...

  4. JQuery+formValidator实现表单验证

    <!-- 需求: 用户注册页面要有用户名.密码.确认密码.邮箱 用户名文本框:用户名不能为空,且必须为数字与字母的6到12位的组合 密码框:密码不能为空,最少6位,包括至少1个大写字母,1个小写 ...

  5. 工程启动没有报错,但是dubbo后台显示没有提供者,工程没有提供服务

    先说一下我遇到的问题:服务工程启动没有异常,消费者工程启动会出现很多nested(嵌套的)错误,但其根本错误是No provider available(缺少服务提供者).可是服务工程起来的时候明明没 ...

  6. Linux下Samba的安装和使用

    一. samba的安装: sudo apt-get insall samba sudo apt-get install smbfs 二. 创建共享目录: mkdir /home/phinecos/sh ...

  7. 4. Go常量

    常量就是那些不可以改变的值 Go语言中定义常量的方式: const a = "admin" 则 a 就是一个常量,但实际上其后面的 "admin" 也是一个字符 ...

  8. LR实现问答系统查询功能

    脚本中未对问题进行参数化处理,关键点在于关联取值和web_add_header()函数的使用 Action() { web_url("首页", "URL=http://q ...

  9. 小强学渲染之Unity Shader边缘描边加强

    项目开发遇到一个需求,就是当坦克的准心瞄准敌方(enemy tank 或 item box)时,要让选中的对象的轮廓高亮起来,这实际上是接下来要讲解的实时渲染中轮廓线的渲染应用.实现方式有多种,下面逐 ...

  10. mysql 文件

    慢查询日志 log_query_time 查询时间超过这个值则会出现在慢查询日志中,默认值是10 log_slow_queries  是否开启慢查询 log_queries_not_using_ind ...