doc: https://docs.spring.io/spring-boot/docs/current/reference/html/
github: https://github.com/spring-projects/spring-boot
- java8
- maven 3.5.3
- mysql 5.6
- tomcat 8.5 (if you build with .war)
Traditionally we will have separate web container like tomcat to deploy .war
file to but Spring boot provide building with "fat jar" that embedded predefine tomcat, so we can java -jar
to start server
When using .war
, we should have ServletInitializer extends SpringBootServletInitializer
To control what final file format build to, we can control in pom.xml
properties <packaging>jar</packaging>
cp -R src\main\resources\config.dev src\main\resources\config.local
mvn install
mvn clean package -Dflyway.configFiles=target\classes\flyway-config.properties flyway:migrate -P local
mvn clean install -P local spring-boot:run
In local env, default will run the application in debug model as defined in pom.xml
with port 5005.
If want run manually, try below
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
We use flyway to do db versioning, as we want more control, we do not directly intergate flyway to spring boot but using flyway maven plugin
flyway provide different commands to help use to controller db migration,
pattern: mvn clean package -Dflyway.configFiles=target\classes\flyway-config.properties flyway:${flyway_action} -P ${env}
most commonly used:
mvn clean package -Dflyway.configFiles=target\classes\flyway-config.properties flyway:info -P local
mvn clean package -Dflyway.configFiles=target\classes\flyway-config.properties flyway:migrate -P local
We only force on integration test
Test case run in different db
To avoid maven test phase in every build life cycle, <maven.test.skip>true</maven.test.skip>
is added to pom.xml to skip test phase
mvn command for test should always add -P testing
parameter
Test log is skipped by configing src/test/resources/logback-test.xml
- update db.url in
config.testing/application.properties
andconfig.testing/flyway-config.properties
- create test db
mvn clean package -Dflyway.configFiles=target\classes\flyway-config.properties flyway:migrate -P testing
- run
mvn test -Dmaven.test.skip=false -P testing
We using spring-actuator to provide health check endpoint
curl localhost:8888/actuator/health
ref: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
Swagger2 default enable for profile local,dev
after server start go http://localhost:8888/swagger-ui.html
create key: keytool -genkey -alias selfsigned_localhost_ssl -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore local_ssl.p12 -validity 3650 -keypass local_ssl -storepass local_ssl
place to resources/
uncomment below in application.properties
#server.ssl.enabled=true
#http.port=8888
#server.port=8444
#server.ssl.key-store=classpath:local_ssl.p12
#server.ssl.key-store-password=local_ssl
#server.ssl.key-store-type=PKCS12
#server.ssl.key-password=local_ssl
There is very good monitoring console using actuator endpoints to visualize data
http://codecentric.github.io/spring-boot-admin/2.0.3/#getting-started
Make use of spring-boot-devtools
, when start with mvn clean install -P local spring-boot:run
, we can call mvn install
in another console, the app will restart
In Intellij, we need start the project with run configuration spring-boot-play [spring-boot:run]
, create you own if not exist, then follow https://stackoverflow.com/a/12744431/5824101 to enable auto compile
configure FileIntegrationConfig to set up channel, channel chain now is
inFileChannel->processFileChannel->${businessLogicChannel}->doneFileChannel
tutorial: https://dzone.com/articles/message-processing-spring
doc: https://docs.spring.io/spring-integration/reference/html/files.html
add all customize to RestClientConfig
using RestTemplateBuilder to build the template.
for the client store business logic, add new class to path com.example.springbootplay.httpclient
default we have LogRequestDetailHttpRequestInterceptor for all http request out bound. If need special handing, need add the Interceptor when injecting RestTemplate bean
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
provide HTTP call routing end point for external consumer, returning data with POJO. Bridge for Service Layer business logic and external consumer
provide business logic implementation. Bridge for Controller Layer and Dao Layer
bride for Service Layer business and database data access, normally using ORM framework to abstract the conversion of database data and business object. Bridge for Service Layer and database
mybatis-plus is used as ORM stack, read the API doc for quick start
stateless function that do not keep any information and not reply on any Service Layer business logic
TBC
It is suggest that using CodeGen intelliJ plug to create dao-service-model template