# webflux-demo **Repository Path**: collinme/webflux-demo ## Basic Information - **Project Name**: webflux-demo - **Description**: 在https://github.com/callicoder/spring-webflux-reactive-rest-api-demo.git 基础上继续项目学习 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-17 - **Last Updated**: 2022-08-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 项目常用命令 [需要环境](https://gitee.com/collinme/docker-data.git) ```docker # 打包 添加-Ddockerfile.arg=test 修改配置文件数据库相关地址,直接使用宿主机数据库 mvn clean package dockerfile:build -Ddockerfile.arg=test #启动 1:建议添加名称 方便进入 2:强烈建议添加 -d 后台启动 # 注意挂载必须使用绝对路径 ~/local/log [本地路径] docker run -v ~/local/logs:/app/logs -dp 8080:8080 --name web webflux-demo:0.0.1-SNAPSHOT # 查看日志 或者使用容器ID进入 docker logs -f --tail=10 web #进入容器 注意镜像版本是alpine-linux 是/bin/sh 而不是ubuntu的/bin/bash docker exec -it web /bin/sh # 停止 docker stop web # 删除 docker rm web ``` ```shell #docker 打包 docker build --build-arg arg=test -t webflux-demo:0.0.1-SNAPSHOT . # docker启动 后面添加 imagesID docker run -dp 8080:8080 webflux-demo:0.0.1-SNAPSHOT ## mvn直接打包传递参数 arg=test mvn clean package dockerfile:build -Ddockerfile.arg=test # 启动 docker run -dp 8080:8080 webflux-demo:0.0.1-SNAPSHOT ``` [结合docker](结合docker) # old ## Build Reactive Rest APIs with Spring WebFlux and Reactive MongoDB Read the tutorial : https://www.callicoder.com/reactive-rest-apis-spring-webflux-reactive-mongo/ ## Requirements 1. Java - 8 2. Maven - 3.x.x 3. MongoDB - 3.x.x ## Steps to Setup **1. Clone the application** ```bash git clone https://github.com/callicoder/spring-webflux-reactive-rest-api-demo.git ``` **2. Build and run the app using maven** ```bash cd spring-webflux-reactive-rest-api-demo mvn package java -jar target/webflux-demo-0.0.1-SNAPSHOT.jar ``` Alternatively, you can run the app without packaging it using - ```bash mvn spring-boot:run ``` The server will start at . ## Exploring the Rest APIs The application defines following REST APIs ``` 1. GET /tweets - Get All Tweets 2. POST /tweets - Create a new Tweet 3. GET /tweets/{id} - Retrieve a Tweet by Id 3. PUT /tweets/{id} - Update a Tweet 4. DELETE /tweets/{id} - Delete a Tweet 4. GET /stream/tweets - Stream tweets to a browser as Server-Sent Events ``` ## Running integration tests The project also contains integration tests for all the Rest APIs. For running the integration tests, go to the root directory of the project and type `mvn test` in your terminal. ### 项目说明 以 https://github.com/callicoder/spring-webflux-reactive-rest-api-demo.git 基础上搭建基础 # 学习笔记 ## 需要知识点 - [ ] 自定义注解 - [x] 用户注册登录(加盐) - 商城页面 - double 分布式 - 数据库分布(主从(多数据源) - nacos 注册中心(zk同款) ## 修改,maven打包方式 使用 java -jar -Dloader.path=lib *.jar 可以启动 https://zhuanlan.zhihu.com/p/363631002 ## 分离lib和配置 ```xml org.apache.maven.plugins maven-jar-plugin true ${project.build.directory}/lib/ ./resources/ ``` ## 结合docker ```xml com.spotify dockerfile-maven-plugin 1.4.0 ${project.name} ${project.version} target/${project.build.finalName}.jar ``` 启动后可执行 http://127.0.0.1:8080/tweets http://127.0.0.1:8080/selectOne?id=1 ### tag 注意点 当前mybatis的测试1和测试2都通过了 同时spring也可以启动 ### 添加拦截器 [](https://blog.csdn.net/sunxiaoju/article/details/109660493) docker启动redis docker run -p 6379:6379 --name redis -v ~/local/docker/redis.conf:/etc/redis/redis.conf -v ~/local/docker/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes ### 数据库加密 ---放弃无法实现 com.github.ulisesbocchio jasypt-spring-boot-starter 2.1.1 ### maven jar 冲突 maven helper 的使用 ![](.Readme_images/mvn-helper.png) 从图中可以看出 springboot已经集成了 slf4j 和 logback-classic 其中如果直接引用出现冲突,最终选择了最高版本 [WARNING] An attempt failed, will retry 1 more times org.apache.maven.plugin.MojoExecutionException: Could not build image at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:185) at com.spotify.plugin.dockerfile.BuildMojo.execute (BuildMojo.java:105) at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute (AbstractDockerMojo.java:246) at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute (AbstractDockerMojo.java:235) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) at org.apache.maven.cli.MavenCli.main (MavenCli.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: com.spotify.docker.client.exceptions.DockerException: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.spotify.docker.client.messages.RegistryAuth` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('desktop') at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: java.util.LinkedHashMap["credsStore"]) at com.spotify.docker.client.auth.ConfigFileRegistryAuthSupplier.authForBuild (ConfigFileRegistryAuthSupplier.java:108) at com.spotify.docker.client.auth.MultiRegistryAuthSupplier.authForBuild (MultiRegistryAuthSupplier.java:77) at com.spotify.docker.client.DefaultDockerClient.build (DefaultDockerClient.java:1406) at com.spotify.docker.client.DefaultDockerClient.build (DefaultDockerClient.java:1383) at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:178) at com.spotify.plugin.dockerfile.BuildMojo.execute (BuildMojo.java:105) at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute (AbstractDockerMojo.java:246) at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute (AbstractDockerMojo.java:235) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) at org.apache.maven.cli.MavenCli.main (MavenCli.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.spotify.docker.client.messages.RegistryAuth` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('desktop') at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: java.util.LinkedHashMap["credsStore"]) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.exc.MismatchedInputException.from (MismatchedInputException.java:63) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch (DeserializationContext.java:1342) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator (DeserializationContext.java:1031) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks (ValueInstantiator.java:371) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString (StdValueInstantiator.java:323) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString (BeanDeserializerBase.java:1366) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther (BeanDeserializer.java:171) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize (BeanDeserializer.java:161) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap (MapDeserializer.java:527) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize (MapDeserializer.java:364) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize (MapDeserializer.java:29) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault (BeanDeserializerBase.java:1276) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject (BeanDeserializer.java:326) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize (BeanDeserializer.java:159) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.ObjectMapper._readValue (ObjectMapper.java:3972) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.ObjectMapper.readValue (ObjectMapper.java:2264) at com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.ObjectMapper.treeToValue (ObjectMapper.java:2746) at com.spotify.docker.client.DockerConfigReader.parseDockerConfig (DockerConfigReader.java:116) at com.spotify.docker.client.DockerConfigReader.fromConfig (DockerConfigReader.java:51) at com.spotify.docker.client.auth.ConfigFileRegistryAuthSupplier.authForBuild (ConfigFileRegistryAuthSupplier.java:106) at com.spotify.docker.client.auth.MultiRegistryAuthSupplier.authForBuild (MultiRegistryAuthSupplier.java:77) at com.spotify.docker.client.DefaultDockerClient.build (DefaultDockerClient.java:1406) at com.spotify.docker.client.DefaultDockerClient.build (DefaultDockerClient.java:1383) at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:178) at com.spotify.plugin.dockerfile.BuildMojo.execute (BuildMojo.java:105) at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute (AbstractDockerMojo.java:246) at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute (AbstractDockerMojo.java:235) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) at org.apache.maven.cli.MavenCli.main (MavenCli.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) [INFO] Building Docker context F:\workspace\webflux-demo [INFO]