Saturday, July 8, 2017

FAQ Questions on Spring Boot

How to control logging with Spring Boot?

By default, the SLF4j Logging is included in the Spring Boot starter package. To enable logging, create a file in the root of the resources folder.


# Logging pattern for the console
logging.pattern.console= "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"

# Logging pattern for file
logging.pattern.file= "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"


Similarly we can configure in application.yml as well.

2. application.yml
    org.springframework.web: ERROR
    com.waheedtechblog: DEBUG
    console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"
    file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
  file: /Users/waheed/application.log

3.  Classic Logback.xml

If you don’t like the Spring Boot logging template, just create a standard logback.xml in the root of the resources folder or root of the classpath. This will override the Spring Boot logging template.

How to run Spring boot application to custom port ?
In, add following property.

How to configure datasource using Spring boot?
• Use either spring-boot-starter-jdbc or spring-boot-starterdata-jpa and include a JDBC driver on classpath
• Declare properties

1.      spring.datasource.url=jdbc:mysql://localhost/test
2.      spring.datasource.username=dbuser
3.      spring.datasource.password=dbpass
4.      spring.datasource.driver-class-name=com.mysql.jdbc.Driver
– Spring Boot will create a DataSource with properties set
– Will even use a connection pool if the library is found on the classpath!

How to change Context Path?
To change the context path, update server.contextPath properties either in file or application.yaml file.



  port: 8080
  contextPath: /application

No comments:

Post a Comment

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...