首页 文章 精选 留言 我的

精选列表

搜索[项目管理软件],共10000篇文章
优秀的个人博客,低调大师

SpringBoot(二)_项目属性配置

修改端口 在main/resources/application.properties修改端口 server.port=8088 此时启动访问localhost:8088/hello 就会看到 Hello Spring Boot! 使用yml文件替换properties 文件 (1)在main/resources 文件下新建一个application.yml 文件 (2)在yml文件中修改端口 server: port: 8099 (3) 删除掉application.properties文件,只保留yml文件 (4) 运行程序,此时访问8099端口即可 获取配置文件的值 (1) 在application.yml 文件中,编写上其他内容 server: port: 8099 name: maomao age: 18 (2) 利用@Value 注解 @RestController public class HelloController { @Value("${name}") private String name; @Value("${age}") private int age; @RequestMapping(value = {"/hello"},method = RequestMethod.GET) public String say(){ return name+age; } } (3)访问8099端口,就获取到值 maomao 18 使用自定义配置类 如果属性很多,我们每个属性都需要写,显得有些费事,我们可以利用自定义配置类进行获取 (1) 修改yml 文件 server: port: 8099 girl: name: maomao age: 18 (2) 创建properties/GirlProperties.java @Component @ConfigurationProperties(prefix = "girl") public class GirlProperties { private String name; private int age; //get和set方法省略 } (3) 我在使用@ConfigurationProperties 这个注解时,提示找不到class,需在pom文件中引入 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> (4) 修改controller文件 @RestController public class HelloController { @Resource private GirlProperties girlProperties; @RequestMapping(value = {"/hello"},method = RequestMethod.GET) public String say(){ return girlProperties.getName(); } } (5)验证结果 maomao 开发环境和生成环境配置不同的问题 这个问题经常见,比如我们开发环境 name 是maomao ,生成环境是 毛毛,我们大部分都是修改配置文件,但是这样还是很麻烦。 (1) 复制2个yml文件,分别是application-dev.yml (开发环境) application-prod.yml(生产环境) (2) 修改application-prod.yml(生产环境)文件 server: port: 8088 girl: name: 毛毛 age: 18 (3) application-dev.yml (开发环境)文件内容 server: port: 8099 girl: name: maomao age: 18 (4)application.yml文件内容,这个就代表使用dev的配置文件 spring: profiles: active: dev (5)上篇文章讲过java -jar 的启动方式 先执行 mvn install 在执行启动 java -jar girl-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod (6)此时就是访问的prod 的配置8088,(注意我们配置的application.yml 中用的是dev 这个配置文件,但是我们启动的时候加上后面的参数就自动切换到 prod 文件上) 总结 在使用yml进行配置更加简单方便,使用java -jar 启动 加上参数,就可以避免我们来回修改配置文件,有漏掉的情况。 源码下载:github 学习不是要么0分,要么100分的。80分是收获;60分是收获;20分也是收获。有收获最重要。但是因为着眼于自己的不完美,最终放弃了,那就是彻底的0分了。

优秀的个人博客,低调大师

Spring Reactor 项目核心库

Reactor Core Non-Blocking Reactive Streams Foundation for the JVM both implementing a Reactive Extensions inspired API and efficient event streaming support. Getting it Reactor 3 requires Java 8 or + to run. With Gradle from repo.spring.io or Maven Central repositories (stable releases only): repositories { // maven { url 'http://repo.spring.io/snapshot' } maven { url 'http://repo.spring.io/milestone' } mavenCentral() } dependencies { //compile "io.projectreactor:reactor-core:3.1.4.RELEASE" //testCompile("io.projectreactor:reactor-test:3.1.4.RELEASE") compile "io.projectreactor:reactor-core:3.2.0.M1" testCompile("io.projectreactor:reactor-test:3.2.0.M1") } See the reference documentation for more information on getting it (eg. using Maven, or on how to get milestones and snapshots). Note about Android support: Reactor 3 doesn't officially support nor target Android. However it should work fine with Android SDK 26 (Android O) and above. See thecomplete note in the reference guide. Getting Started New to Reactive Programming or bored of reading already ? Try the Introduction to Reactor Core hands-on ! If you are familiar with RxJava or if you want to check more detailled introduction, be sure to checkhttps://www.infoq.com/articles/reactor-by-example ! Flux A Reactive Streams Publisher with basic flow operators. Static factories on Flux allow for source generation from arbitrary callbacks types. Instance methods allows operational building, materialized on each Flux#subscribe(), Flux#subscribe() or multicasting operations such as Flux#publish and Flux#publishNext. <img src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.3.RELEASE/src/docs/marble/flux.png" width="500"> Flux in action : Flux.fromIterable(getSomeLongList()) .mergeWith(Flux.interval(100)) .doOnNext(serviceA::someObserver) .map(d -> d * 2) .take(3) .onErrorResumeWith(errorHandler::fallback) .doAfterTerminate(serviceM::incrementTerminate) .subscribe(System.out::println); Mono A Reactive Streams Publisher constrained to ZERO or ONE element with appropriate operators. Static factories on Mono allow for deterministic zero or one sequence generation from arbitrary callbacks types. Instance methods allows operational building, materialized on each Mono#subscribe() or Mono#get() eventually called. <img src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.3.RELEASE/src/docs/marble/mono.png" width="500"> Mono in action : Mono.fromCallable(System::currentTimeMillis) .flatMap(time -> Mono.first(serviceA.findRecent(time), serviceB.findRecent(time))) .timeout(Duration.ofSeconds(3), errorHandler::fallback) .doOnSuccess(r -> serviceM.incrementSuccess()) .subscribe(System.out::println); Blocking Mono result : Tuple2<Long, Long> nowAndLater = Mono.zip( Mono.just(System.currentTimeMillis()), Flux.just(1).delay(1).map(i -> System.currentTimeMillis())) .block(); Schedulers Reactor uses a Scheduler as a contract for arbitrary task execution. It provides some guarantees required by Reactive Streams flows like FIFO execution. You can use or create efficient schedulers to jump thread on the producing flows (subscribeOn) or receiving flows (publishOn): Mono.fromCallable( () -> System.currentTimeMillis() ) .repeat() .publishOn(Schedulers.single()) .log("foo.bar") .flatMap(time -> Mono.fromCallable(() -> { Thread.sleep(1000); return time; }) .subscribeOn(Schedulers.parallel()) , 8) //maxConcurrency 8 .subscribe(); ParallelFlux ParallelFlux can starve your CPU's from any sequence whose work can be subdivided in concurrent tasks. Turn back into a Flux with ParallelFlux#sequential(), an unordered join or use abitrary merge strategies via 'groups()'. Mono.fromCallable( () -> System.currentTimeMillis() ) .repeat() .parallel(8) //parallelism .runOn(Schedulers.parallel()) .doOnNext( d -> System.out.println("I'm on thread "+Thread.currentThread()) ) .subscribe() Custom sources : Flux.create and FluxSink, Mono.create and MonoSink To bridge a Subscriber or Processor into an outside context that is taking care of producing non concurrently, use Flux#create, Mono#create. Flux.create(sink -> { ActionListener al = e -> { sink.next(textField.getText()); }; // without cancellation support: button.addActionListener(al); // with cancellation support: sink.onCancel(() -> { button.removeListener(al); }); }, // Overflow (backpressure) handling, default is BUFFER FluxSink.OverflowStrategy.LATEST) .timeout(3) .doOnComplete(() -> System.out.println("completed!")) .subscribe(System.out::println) The Backpressure Thing Most of this cool stuff uses bounded ring buffer implementation under the hood to mitigate signal processing difference between producers and consumers. Now, the operators and processors or any standard reactive stream component working on the sequence will be instructed to flow in when these buffers have free room AND only then. This means that we make sure we both have a deterministic capacity model (bounded buffer) and we never block (request more data on write capacity). Yup, it's not rocket science after all, the boring part is already being worked by us in collaboration with Reactive Streams Commons on going research effort. What's more in it ? "Operator Fusion" (flow optimizers), health state observers, helpers to build custom reactive components, bounded queue generator, hash-wheel timer, converters from/to Java 9 Flow, Publisher and Java 8 CompletableFuture. The repository contains a reactor-test project with test features like the StepVerifier. Reference Guide http://projectreactor.io/docs/core/release/reference/docs/index.html Javadoc https://projectreactor.io/docs/core/release/api/ Getting started with Flux and Mono https://github.com/reactor/lite-rx-api-hands-on Reactor By Example https://www.infoq.com/articles/reactor-by-example Head-First Spring & Reactor https://github.com/reactor/head-first-reactive-with-spring-and-reactor/ Beyond Reactor Core Everything to jump outside the JVM with the non-blocking drivers from Reactor Netty. Reactor Addons provide for adapters and extra operators for Reactor 3. Powered by Reactive Streams Commons Licensed under Apache Software License 2.0 Sponsored by Pivotal

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册