boot

spring boot + kafka 使用详细步骤

匿名 (未验证) 提交于 2019-12-03 00:25:02
一,Kafka的安装以及配置 1.下载文件 wget http://mirror.bit.edu.cn/apache/kafka/0.11.0.0/kafka_2.11-0.11.0.0.tgz 1 2 2.安装 tar xzvf kafka_2.11-0.11.0.0.tgz -C /usr/local/ 1 2 3.配置(服务器在阿里云ECS上) vi %kafka_home%/server.properties ############################# Server Basics ############################# broker.id=0 port=9092 host.name=阿里云内网ip advertised.host.name=阿里云外网ip delete.topic.enable=true ....其他的配置不变 1 2 3 4 5 6 7 8 9 10 11 二,Spring boot操作Kafka 1.Spring boot pom依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version>

Execution default of goal org.springframework.boot:spring-boot-maven-plugin: XXXX .RELEASE:repackage

匿名 (未验证) 提交于 2019-12-03 00:22:01
Spring boot 执行打包操作时候,报错如下 Execution default of goal org.springframework.boot:spring-boot-maven-plugin:XXXX RELEASE:repackage failed: Unable to find main class 根源为,在我的项目场景下, 只有如图的-boot子模块生产可执行JAR包,其他几个模块是不需要可执行的,而我的根POM里,spring boot 默认帮我加入了如下build策略 < build > < plugins > < plugin > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-maven-plugin </ artifactId > </ plugin > </ plugins > </ build > 解决方案比较简单,就是把这个spirng boot针对所有模块的build部分移除出来,放到你自己需要打包的那个子模块里,我这里是api-service-boot模块,其他模块不需要生产可执行的jar. 文章来源: Execution default of goal org.springframework.boot:spring-boot-maven

Spring Boot 内嵌容器Undertow

匿名 (未验证) 提交于 2019-12-03 00:22:01
Spring Boot内嵌容器支持Tomcat、Jetty、Undertow。为什么选择Undertow? 这里有一篇文章,时间 2017年1月26日发布的: Tomcat vs. Jetty vs. Undertow: Comparison of Spring Boot Embedded Servlet Containers 这篇文章详细测试了Spring Boot应用在三种容器下的性能和内存使用,内含完整的测试代码和测试流程。证明了Undertow在性能和内存使用上是最好的。 在Spring Boot中使用 Undertow 而不是 Tomcat 1、Maven示例: < dependency > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-web </ artifactId > < exclusions > < exclusion > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-tomcat </ artifactId > </ exclusion > </ exclusions > </ dependency > <

Spring Boot 注解方式自定义Endpoint

匿名 (未验证) 提交于 2019-12-03 00:22:01
概述 在使用Spring Boot的时候我们经常使用actuator,健康检查,bus中使用/refresh等。这里记录如何使用注解的方式自定义Endpoint。可用于满足一些服务状态监控,或者优雅停机等。 准备 Spring Boot项目,pom中加入: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> 编写自定义Endpoint @Configuration @Endpoint(id = "my-endpoint") public class MyEndpoint { @ReadOperation public Map<String, Object> endpoint() { Map<String, Object> map = new HashMap<>(16); map.put("message", "this is my endpoint"); return map; } } 配置 management.endpoints.web.exposure.include=my-endpoint 启动&测试 启动后可以看到日志: Mapped "{[/actuator/my

Spring Boot 注解方式自定义Endpoint

匿名 (未验证) 提交于 2019-12-03 00:22:01
概述 在使用Spring Boot的时候我们经常使用actuator,健康检查,bus中使用/refresh等。这里记录如何使用注解的方式自定义Endpoint。可用于满足一些服务状态监控,或者优雅停机等。 准备 Spring Boot项目,pom中加入: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> 编写自定义Endpoint @Configuration @Endpoint(id = "my-endpoint") public class MyEndpoint { @ReadOperation public Map<String, Object> endpoint() { Map<String, Object> map = new HashMap<>(16); map.put("message", "this is my endpoint"); return map; } } 配置 management.endpoints.web.exposure.include=my-endpoint 启动&测试 启动后可以看到日志: Mapped "{[/actuator/my

Spring Boot(三)--Servlet

匿名 (未验证) 提交于 2019-12-03 00:22:01
Web开发使用 Controller 基本上可以完成大部分需求,但是我们还可能会用到 Servlet、Filter、Listener、Interceptor 等等。 Spring boot 的主 Servlet 为 DispatcherServlet,其默认的url-pattern为“/”。也许我们在应用中还需要定义更多的Servlet,该如何使用SpringBoot来完成呢? 也可以通过实现 ServletContextInitializer 接口直接注册。 二、在 SpringBootApplication 上使用@ServletComponentScan 注解后,Servlet、Filter、Listener 可以直接通过 @WebServlet、@WebFilter、@WebListener 注解自动注册,无需其他代码。 通过代码注册Servlet示例代码: SpringBootSampleApplication.java package org.springboot.sample; import org.springboot.sample.servlet.MyServlet; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure

初遇Spring Boot

匿名 (未验证) 提交于 2019-12-03 00:22:01
一 Spring Boot的角色 二 Spring Boot 2.0新特性 编程语言:Java 8+、Kotlin 底层框架:Spring Framwork 5.0.x 全新特性:Web Flux 三 为什么选择Web Flux 函数编程:Java 8 Lambda 响应编程:Reactive Stresms 异步编程:Servlet 3.1或Asyc NIO 四 Spring Boot环境准备 https://www.imooc.com/video/16350 五 maven相关配置 下载地址地址: http://maven.apache.org/ 2 本地仓储和阿里云镜像配置 <localRepository>D:/.m2/repos</localRepository> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url>; <mirrorOf>central</mirrorOf> </mirror> 3 环境变量配置 4 IDEA开发环境配置 文章来源: 初遇Spring Boot

Springboot启动时报“run failed: Unable to find a single main class from the following candidates“

匿名 (未验证) 提交于 2019-12-03 00:22:01
一、现象描述 Spring boot启动时报错误如下: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project SpringBootHotDeploy: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run failed: Unable to find a single main class from the following candidates [com.queen.controller.HotDeployAPP, com.queen.controller.APP] -> [Help 1] 从字面上理解就是无法从下列候选项中找到单个主类。这个问题笔者遇到时候比较懵逼,后来发现自己建了两个APP类,导致启动服务无法判断到底要启动哪一个APP类。 二、解决办法 解决方案很简单:删除一个你想要删除的APP就可以了 =======欢迎大家拍砖,小手一抖,多多点赞哟!======= 版权声明:本文为博主原创文章,允许转载,但转载必须标明出处。 文章来源:

spring boot 实现原理

匿名 (未验证) 提交于 2019-12-03 00:22:01
前阵子在分析sprng boot的源代码,有了些感悟和心得,今天写篇博客和大家分享下。先来段题外话,在人体的血液中含有血细胞,而血细胞又大致可以分为红细胞、白细胞、血小板。它们各自有各自的用处和特点,互相协作保障人体的建康。 一. 各种Bean 如果我们把Spring想象成人体,把Bean当做细胞的话,那么正是不同种类bean的相互协作才使得spring这个大工厂正常运行,有些bean做管理工作,有些bean为其它bean服务器,有些bean生产其它bean,有些bean承载了应用的业务逻辑。根据我目前的认知,我觉得spring中的bean根据作用可以划分为“普通bean”、“容器后处理器”、“bean后处理器”、“工厂bean”、“工厂方法bean” 这五大类。 普通bean :我这里指的是普通的用户配置的实现应用业务逻辑的bean,比如Dao Bean 或 Service Bean。 容器后处理器bean :这类bean它是为Spring容器服务的,实现了容器后处理器接口。比如像PropertySourcesPlaceholderConfigurer,它的作用就是在创建bean定义对象之前,解析用户配置的非线性值(${..})。 bean后处理器 :这类bean它是为其它bean服务的,实现了bean后处理接口。这类bean可以在创建其它bean过程中的各个环节执行干预操作