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. 线程之Callable、Future 和FutureTask使用及源码分析

    一.Callable 我们知道启动线程有以下两种方式(jdk源码注释中官方定义只有两种启动方式,callable不算线程启动方式) 原文链接:http://www.studyshare.cn/blog ...

  2. 云栖大会day2总结 上午

    第二天上午主要是参与了开发者专场 上 09:00-09:40 线上线下融合时代的工程师成长 李佩 饿了么高级算法总监 09:40-10:20 如何统一阿里巴巴代码规范:探寻工程师文化之路 玄坛 阿里巴 ...

  3. 从servlet规范说起

    servlet规范 1 servlet 3.1规范 1.1 What is servlet A servlet is a JavaTM technology-based Web component, ...

  4. jquery中val属性操作

  5. python学习Day13 函数的嵌套定义、global、nonlocal关键字、闭包及闭包的运用场景、装饰器

    复习 1.函数对象:函数名 => 存放的是函数的内存地址1)函数名 - 找到的是函数的内存地址2)函数名() - 调用函数 => 函数的返回值 eg:fn()() => fn的返回值 ...

  6. Django 自带登录验证:authenticate和login,login_require,logout模块

    验证之前需要在settings 中指定验证数据models AUTH_USER_MODEL = 'crm.UserProfile'#app名字.表名字 1.authenticate是一个方法,验证账号 ...

  7. web应用程序+HTTP协议

    标签(空格分隔): Django web应用程序案例: 如果我们想通过自己电脑访问京东,就是一个网络编程(因为京东的服务部署在京东,通过自己的电脑浏览器传输到京东服务就是网络编程):只要涉及到网络编程 ...

  8. JAVA8 Stream集合操作:中间方法和完结方法

    StreamLambda为java8带了闭包,这一特性在集合操作中尤为重要:java8中支持对集合对象的stream进行函数式操作,此外,stream api也被集成进了collection api, ...

  9. 前端生成pdf

    https://stackoverflow.com/questions/31610129/pdfmake-html-table-to-pdfmake-table https://www.jianshu ...

  10. mysql,查询时间戳

    1.查询当前时间1天前的时间点   select date_sub(now() ,interval 1 day)   2.查询当前时间的时间1天之后的时间点   select data_sub(now ...