Giter VIP home page Giter VIP logo

xuexiangjys / xupdateservice Goto Github PK

View Code? Open in Web Editor NEW
218.0 6.0 69.0 36.79 MB

Use Spring Boot easy build, Gradle build, and provide update service for XUpdate.(使用Spring Boot简易搭建,Gradle构建,为XUpdate提供更新服务)

Home Page: https://github.com/xuexiangjys/XUpdate/wiki

License: Apache License 2.0

Java 93.85% CSS 2.07% HTML 2.23% JavaScript 1.86%
spring-boot mybatis gradle mysql aop-aspectj xupdate

xupdateservice's Introduction

XUpdateService

使用Spring Boot简易搭建,Gradle构建,为XUpdate提供的更新服务。

内容

  • 使用spring boot快速搭建,并使用Gradle进行构建【区别Maven】。

  • 使用阿里的druid数据库连接池和tk.mybatis进行数据库的连接。

  • 使用MySql作为数据库。

  • 提供了应用版本后台管理所需的API服务,使用Html和ajax简单实现了应用版本管理界面。

  • 使用了AOP对api请求进行动态日志记录。

  • 实现通用的文件上传(包括多文件上传)和下载功能。

  • 增加了请求流量以及请求权限的控制。

  • 支持浏览器跨域请求。

搭建方法

  1. clone项目到本地
git clone https://github.com/xuexiangjys/XUpdateService.git

2.使用IntelliJ IDEA 导入该项目。

3.进行本地数据库的配置。

因为使用的是MySql数据库,如果你电脑上没有安装MySql的话,请先点击安装。你可以安装MySQL Community ServerMySQL Workbench,建议下载的MySql版本是5.7。

  • MySql安装完成后,请执行根目录下sql文件夹下的脚本,创建数据库表和内容。

  • 配置src/main/resources/application.yml文件,包括服务端口、数据库配置、mybatis配置、文件上传配置等。

  • 如果你需要使用mybatis的自动生成代码脚本generator,请配置src/main/resources/db-mysql.properties文件,然后执行./gradlew mybatisGenerate或者在Gradle的Task列表中选择mybatisGenerate双击即可。

4.直接运行XUpdateServiceApplication即可运行服务。

程序打包

1.执行./gradlew bootJar或点击Gradle任务栏点击Tasks -> Build -> bootJar.

2.打包后的是jar文件,打包路径:build/libs/ 下,如下图:

3.最后执行jar包即可.

java -jar build/libs/xxxxx.jar

4.目前最新的已打包好的jar在项目的Packagexupdateservice-1.0.0.jar, 运行前请保证你的数据库连接正常。

版本更新管理后台

由于使用Java编写web管理后台不是很好看,因此我特地去学习了最近比较火的Vue.js编写了一个简洁优美的管理后台供大家参考。

项目地址: https://github.com/xuexiangjys/xupdate-management

项目预览


API构成

管理接口

1、注册APK的版本信息

  • 请求类型: post
  • url : /update/addVersionInfo
  • 参数 :
{
    "updateStatus":2,
    "modifyContent":"1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。",
    "appKey":"test",
    "versionName":"1.0.3",
    "versionCode":4
}
  • 响应 :
{
    "Msg":"",
    "Code":0,
    "Data":{
        "versionId":12,
        "updateStatus":2,
        "modifyContent":"1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。",
        "appKey":"test",
        "versionName":"1.0.3",
        "versionCode":4
    }
}

2、上传APK

  • 请求类型: post【multipart/form-data】
  • url : /update/uploadApk
  • 参数 :
file=[文件]
versionId=12
  • 响应 :
{
    "Code":0,
    "Msg":"",
    "Data":true
}

3、添加版本信息

  • 请求类型: post【multipart/form-data】
  • url : /update/addAppVersion
  • 参数 :
file=[文件]

appVersionInfo= {
    "updateStatus":2,
    "modifyContent":"1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。",
    "appKey":"test",
    "versionName":"1.0.3",
    "versionCode":4
}

  • 响应 :
{
    "Code":0,
    "Msg":"",
    "Data":true
}

版本更新接口

1、版本信息检查

  • 请求类型: post
  • url : /update/checkVersion
  • 参数 :
versionCode=1,
appKey=com.xuexiang.xupdatedemo 
  • 响应 :
{
    "Msg":"",
    "Code":0,
    "Data":{
        "apkMd5":"E4B79A36EFB9F17DF7E3BB161F9BCFD8",
        "versionId":11,
        "updateStatus":1,
        "downloadUrl":"xupdate_demo_1.0.2.apk",
        "modifyContent":"1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。",
        "appKey":"com.xuexiang.xupdatedemo",
        "apkSize":1649,
        "uploadTime":"2018-07-30 09:47:25",
        "versionName":"1.23.4",
        "versionCode":34
    }
}

2、最新版本下载

  • 请求类型: get
  • url : /update/apk/{fileName:.+}
  • 响应 : 文件流

xupdateservice's People

Contributors

donotlb avatar wuujiawei avatar xuexiangjys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xupdateservice's Issues

个人整理的部署指南

配置xupdate-services 工程和 xupdate-management UI界面

git clone [email protected]:xuexiangjys/XUpdateService.git

1 用intellij引入工程 ,大部分操作作者都说明的很清楚了,可以看文档。

2 修改数据库连接: db-mysql.properties

  修改启动端口等  application.yml

3 现在通过sql目录中 xupdate.sql 创建表,可以先在mysql 中创建xupdate的库。

3 更新依赖(我通过intellij自动引入的,不知道更新命令)

4 直接点run启动,这里没有找到springboot工程的ui,但是通过postman可以调用到接口,很顺利。

5 引入 https://github.com/xuexiangjys/xupdate-management vue管理界面工程

git clone 到本地,然后npm install  

npm run preview 预览工程,也可以将dist目录放入tomcat或者iis中,设置index.html为首页就可以看到管理界面,点击登陆可以直接连上你之前的 XUpdateService 上1111接口来访问了,关于用户密码可以再mysql中查看。

6.测试了一下 xupdate-services 界面尝试登陆和上传没什么问题,就可以部署到服务器上了。

7.打jar包,我跟作者不一样的是使用的是maven命令 :clean package

图片

这里需要注意的是 pom.xml中 org.apache.maven.plugins 中 exclude需要注释掉不然打出来的包运行会报 Cannot determine embedded database driver class for database type NONE,这个错误折腾了一天,尝试了作者的gradle打包也没有成功。后来也是请教了熟悉springboot的同事

下面就是修改之后的代码

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <excludes>
            <!--<exclude>*.txt</exclude>-->
            <!--<exclude>*.xml</exclude>-->
            <!--<exclude>*.properties</exclude>-->
            <!--<exclude>*.yml</exclude>-->
        </excludes>
    </configuration>
</plugin>

8.上传至服务器 ,创建start.sh来启动

java -jar xupdate.jar > ./log.txt 

9 服务器上安装jdk 和 mysql 可以见这里的安装方法
https://www.cnblogs.com/toutou/p/9670395.html

ps .自己遇到额外的问题,react-native 突然又不能自动更新 bundle包,找了根据问题尝试了adb daemon 端口检查关闭重启,然并卵,后来通过启动debuger 日志看到  Metro Bundler 8081 连接不上, 解决设置 解决

集成 xupdate 到android 工程中

1.可以先下载作者的 https://github.com/xuexiangjys/XUpdate工程在As中打开,修改 mUpdateUrl 为之前服务器的地址。

2运行起来尝试一下下载,成功后在把 bulde.gradle 文件和你自己工程的对比合并一下,按照说明,配置自己的bulde.gradle

3 在启动类 MainApplication 中添加

@OverRide
public void onCreate() {
super.onCreate();
XUtil.init(this);
XUtil.debug(true);
initXHttp();
initOKHttpUtils();
initUpdate();
}

private void initUpdate() {
/* XUpdate.newBuild(this).updateParser(new XUpdateServiceParser());*/
XUpdate.get()
.debug(true)
// .isWifiOnly(true) //默认设置只在wifi下检查版本更新
// .isGet(false) //默认设置使用get请求检查版本
.isAutoMode(false) //默认设置非自动模式,可根据具体使用配置
.param("versionCode", UpdateUtils.getVersionCode(this)) //设置默认公共请求参数 UpdateUtils.getVersionCode(this)
.param("appKey",getPackageName()) //.param("appKey", getPackageName())
.setOnUpdateFailureListener(new OnUpdateFailureListener() { //设置版本更新出错的监听
@OverRide
public void onFailure(UpdateError error) {
if (error.getCode() != CHECK_NO_NEW_VERSION) { //对不同错误进行处理
// ToastUtils.toast(error.toString());
Log.d("mainAplication",error.toString());
}
}
})
.supportSilentInstall(true) //设置是否支持静默安装,默认是true
.setIUpdateHttpService(new OKHttpUpdateHttpService()) //这个必须设置!实现网络请求功能。
.init(this); //这个必须初始化

}
private void initXHttp() {
XHttpSDK.init(this); //初始化网络请求框架,必须首先执行
XHttpSDK.debug("XHttp"); //需要调试的时候执行
XHttp.getInstance().setTimeout(20000);
}
private void initOKHttpUtils() {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(20000L, TimeUnit.MILLISECONDS)
.readTimeout(20000L, TimeUnit.MILLISECONDS)
.build();
OkHttpUtils.initClient(okHttpClient);
}

4 会有很多报错,和找不到类,所以我又去把作者的xupdate-lib类加载了进来

implementation project(':xupdate-lib')
  1. 然后实现 OKHttpUpdateHttpService XHttpUpdateHttpService 这些wiki当中说的。

集成这些模块的时候,我遇到两个问题,一个是 点击更新总是提示版本已经是最新,首先通过日志分析看不出啥问题,后来断点发现这里是工程默认调用的下载数据解析类对比不了版本号,修改为

XUpdate.newBuild(getCurrentActivity())
 .updateParser(new XUpdateServiceParser())

还有一些问题就再运行时,有一些Android组件库可能不兼容导致的运行时报错 ,需要用androidx替换 android.support.v4 相关的xml标签,可以根据具体错误百度一下。
最后上一张更新成功的图,有问题可以再github @我,祝大家都成功上线。

图片

ps 遇到的额外问题,作者的xupdate 工程导入到低版本 as中启动不了,提示当前gradle版本太低了,修改了版本号还是不行,后来估计是daemon的问题。升级了as 再启动工程OK了

搞了两天用作者的Gradle打包,也试了Maven,完全不改打包都是报错的。最后新建个项目两分钟搞定

贴个报错信息

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
        at com.xuexiang.xupdateservice.XUpdateServiceApplication.main(XUpdateServiceApplication.java:12)
        ... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 9 more

后台服务自动关停

后台服务只改了端口和数据源,用gradle打包发布,一开始一切正常,但是在运行两个多小时后自动关停,期间就开始启动时使用了下,闲置了两个多小时。没报任何错误。只有两行日志。

2022-10-14 13:53:31.467 INFO 1985999 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closing ...
2022-10-14 13:53:31.474 INFO 1985999 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed

static resource

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Dec 11 11:34:15 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available

请教一下,打成jar包后运行后:Cannot determine embedded database driver class for database type NONE

java -jar xupdate.jar 报错:

WARN 24080 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountController': Unsatisfied dependency expressed through field 'accountService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountService': Unsatisfied dependency expressed through field 'accountMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountMapper' defined in URL [jar:file:/E:/JavaProject/XUpdateService/target/xupdate.jar!/BOOT-INF/classes!/com/xuexiang/xupdateservice/mapper/AccountMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

再开发模式没有问题,请问一下这个该怎么配置

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.