Saturday, February 27, 2021

Spring official document note

 https://docs.spring.io/spring-boot/docs/

1.

If you need to find out what auto-configuration is currently being applied, and why, start your application with the --debug switch. 

2.

To disable devtools, exclude the dependency or set the -Dspring.devtools.restart.enabled=false system property.

3.

With ApplicationStartup, Spring Framework allows you to track the application startup sequence with StartupSteps. This data can be collected for profiling purposes, or just to have a better understanding of an application startup process.

public static void main(String[] args) { SpringApplication app = new SpringApplication(MySpringConfiguration.class); app.setApplicationStartup(new BufferingApplicationStartup(2048)); app.run(args); }

4.

By default, SpringApplication converts any command line option arguments (that is, arguments starting with --, such as --server.port=9000) to a property and adds them to the Spring Environment. As mentioned previously, command line properties always take precedence over file based property sources.

If you do not want command line properties to be added to the Environment, you can disable them by using SpringApplication.setAddCommandLineProperties(false).

5.

Spring Boot does not provide any built in support for encrypting property values, however, it does provide the hook points necessary to modify values contained in the Spring Environment. The EnvironmentPostProcessor interface allows you to manipulate the Environment before the application starts. See Customize the Environment or ApplicationContext Before It Starts for details.

If you’re looking for a secure way to store credentials and passwords, the Spring Cloud Vault project provides support for storing externalized configuration in HashiCorp Vault.

6.

By default, if you use the “Starters”, Logback is used for logging. 

7.

Spring MVC uses the HttpMessageConverter interface to convert HTTP requests and responses. Sensible defaults are included out of the box. 

8.

By default, Spring Boot serves static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext. It uses the ResourceHttpRequestHandler from Spring MVC so that you can modify that behavior by adding your own WebMvcConfigurer and overriding the addResourceHandlers method.

9.

Spring Boot includes auto-configuration support for the following templating engines:

When you use one of these templating engines with the default configuration, your templates are picked up automatically from src/main/resources/templates.
10.

health

Shows application health information.

httptrace

Displays HTTP trace information (by default, the last 100 HTTP request-response exchanges). Requires an HttpTraceRepository bean.

info

Displays arbitrary application info.

integrationgraph

Shows the Spring Integration graph. Requires a dependency on spring-integration-core.

loggers

Shows and modifies the configuration of loggers in the application.

By default, all endpoints except for shutdown are enabled. To configure the enablement of an endpoint, use its management.endpoint.<id>.enabled property. 

* can be used to select all endpoints. For example, to expose everything over HTTP except the env and beans endpoints, use the following properties:
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.exclude=env,beans

If Spring Security is present, endpoints are secured by default using Spring Security’s content-negotiation strategy. 

11.
If you are developing a web application, Spring Boot Actuator auto-configures all enabled endpoints to be exposed over HTTP. The default convention is to use the id of the endpoint with a prefix of /actuator as the URL path. For example, health is exposed as /actuator/health.
HTTP Tracing can be enabled by providing a bean of type HttpTraceRepository in your application’s configuration. For convenience, Spring Boot offers an InMemoryHttpTraceRepository that stores traces for the last 100 request-response exchanges, by default. InMemoryHttpTraceRepository is limited compared to other tracing solutions and we recommend using it only for development environments. For production environments, use of a production-ready tracing or observability solution, such as Zipkin or Spring Cloud Sleuth, is recommended. Alternatively, create your own HttpTraceRepository that meets your needs.




12.
Add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

http://localhost:8080/actuator/beans
http://localhost:8080/actuator/env
http://localhost:8080/actuator/health
http://localhost:8080/actuator/httptrace   does not work
    The functionality has been removed by default in Spring Boot 2.2.0. 
http://localhost:8080/actuator/info 
http://localhost:8080/actuator/loggers
http://localhost:8080/actuator/metrics
http://localhost:8080/actuator/mappings 



Monday, February 22, 2021

Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud

 

https://github.com/PacktPublishing/Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud

 To see the code being executed, please visit the following: http://bit.ly/2kn7mSp.

 I prefer using constructor injection (over field and setter injection) to keep the state in my components immutable. 

 The immutable state is important if you want to be able to run the component in a multithreaded runtime environment.

Tuesday, February 9, 2021

Linux add user into group

 Command: 

sudo /usr/sbin/usermod -a -G jboss $USER (one time efffort in your login whenever VM rebuilt to allow to edit file in "jboss jboss")


The people can run himself and logout, re-login,

Check "groups THEID | grep jboss" 


Thursday, February 4, 2021

MAC Crontab testing

 MAC Crontab testing

28 * * * * cd ~/auspix && ./hello.sh

@reboot cd ~/auspix && ./hello2.sh

1. It won't run before the login, even if added into Login Items. (Unless enable auto login)

2. After login, it will run when the screen is locked or the user is switched

3. When MAC is power on, another user logins, the crontab user doesn't login yet, the crontab will run

4. Before the login, MAC screen shows GMT time instead of local time!


Tuesday, February 2, 2021

沪深股票自动交易之交易执行

自动交易大概可以分为数据获取、交易策略、回归测试以及交易执行,做为小散,CTP/FIX等不适用,破解通达信DLL,会担心安全问题,比较合适的还是控制键盘鼠标来执行交易。

拿我使用的华泰证券来说,之前一直用AutoIt来做交易,但这个有两个问题,一是华泰证券升级之后,得做相应的改动,比如拷贝数据要输入验证码什么的。另一个问题是,因为身在国外的原因,连接华泰证券各站点,速度慢且不稳定,ping起来最少也有200多ms,甚至不能ping通。后来发现有个python的easytrader,简单又好用,感谢作者shidenggui。

第二个问题,曾经试过用google cloud,但必须在云主机上在安装VirtualBox,在VirtualBox上安装Windows XP,直接在google cloud上断开远程桌面后自动化的UI无法执行(解决方法见后)。easytrader不支持windows XP,如果在云主机上再安装windows 7/10的话,需要云主机很好的配置才可能。具体可参见这篇文章:如何关闭远程桌面后仍处于可交互状态

前几天试了一下腾讯云,意外发现在腾讯云的1核 2GB 1Mbps的标准型SA2主机上运行起来如行云流水,ping值只有20多ms,而且通过这位仁兄介绍的方法,远程桌面断开后也工作的很好。另外一种方式是用如shengdenggui推荐的TightVNC。设置windows自动登录,然后在交易前重新启动一下机器,定时运行的交易程序也会照常运行。

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (

  %windir%\System32\tscon.exe %%s /dest:console

)