26 Temmuz 2020 Pazar

SpringBoot spring.server Ayarları

Giriş
Genel embedded web server ayarları içindir. Altta kullanılan servlet sunucusu (tomcat, netty) fark etmez. Açıklaması şöyle.
All of the server.* properties that Spring Boot supports only apply to the configuration of the embedded servlet container  (Tomcat, Jetty, or Undertow).
spring.application.name Alanı
Bu alan uygulamamız bir yere register olacaksa kullanılır.
Örnek
Şöyle yaparız
spring:
 application:
  name: gateway
 main:
  web-application-type: SERVLET 


server:
 servlet:
  context-path: /gateway
 port: 8080
spring.main.web-application-type Alanı
Örnek
Embedded web server'ı devre dışı bırakmak için şöyle yaparız. Örneğin sadece HTTP çağrıları yapacak bir uygulamada Embedded Tomcat kullanmaya gerek olmaz.
spring.main.web-application-type= none
Compression

spring.server.error Alanı
Örnek
include-message alanı always değilse çıktı olarak şunu alırız. message alanı boştur
{
  "timestamp": "2020-11-28T13:24:02.239+00:00",
  "status": 500,
  "error": "Internal Server Error",
  "message": "",
  "path": "/product/1"
}
Şöyle yaparız
server:
  error:
  include-message: always
  include-binding-errors: always
  include-stacktrace: on_trace_param
  include-exception: false
include-message alanı always değilse çıktı olarak şunu alırız. message alanı doludur
{
"timestamp": "2020-11-29T09:42:12.287+00:00", "status": 500, "error": "Internal Server Error", "message": "Item with id 1 not found", "path": "/product/1" }
Eğer URL'den sonra "?trace=true" eklersek bu sefer trace isimli bir alan daha gönderilir.
çıktı olarak şunu alırız. trace alanı eklenir.
{
"timestamp": "2020-11-29T09:42:12.287+00:00", "status": 500, "error": "Internal Server Error", "message": "Item with id 1 not found", "trace": "foo.exception.NoSuchElementFoundException: Item with id 1 not found...", "path": "/product/1" }
spring.server.http2.enabled Alanı
Açıklaması şöyle.
You can enable HTTP/2 support in your Spring Boot application with the server.http2.enabled configuration property. This support depends on the chosen web server and the application environment, since that protocol is not supported out-of-the-box by JDK8. Spring Boot does not support h2c, the cleartext version of the HTTP/2 protocol. So you must configure SSL first.
Şöyle yaparız
# Enable HTTP/2 support, if the current environment supports it server.http2.enabled=true
Multipart Upload Ayarları
Açıklaması şöyle
By default, Spring Boot allows you to upload a file with a maximum size of 1MB.
Şöyle yaparız
spring.servlet.multipart.enabled=true # Write files to disk if the file size is more than 2KB. spring.servlet.multipart.file-size-threshold=2KB # The intermediate disk location where the uploaded files are written spring.servlet.multipart.location=/tmp # Maximum file size that can be uploaded spring.servlet.multipart.max-file-size=50MB # Maximum allowed multipart request size spring.servlet.multipart.max-request-size=75MB
spring.server.shutdown

server.servlet.context-path Alanı
Spring normalde tomcat'i "/" ile başlatır. Bu parametre ile örneğin "/mycontext" ile başlatabiliriz. Açıklaması şöyle
By default, Spring Boot runs your application on port 8080 with the context path /.

If you wanna change the default port and context path, then it’s just a matter of specifying the corresponding values in the application.properties file
Şöyle yaparız
# HTTP Server port server.port=8080 # Make the application accessible on the given context path (http://localhost:8080/myapp) server.servlet.context-path=/myapp
server.servlet.session
Bu başlığın altında bir çok alan var. SpringBoot spring.server Session Ayarları yazısına taşıdım.

server.port Alanı
Kullanılacak portu atamak için şöyle yaparız
server.port = 8090
Browser Caching Ayarları
Açıklaması şöyle
Browser caching is another way to improve the page load speed of your website. You can set cache-control headers to tell browsers to cache static resources until a certain period of time.

Browser caching is disabled by default in Spring Boot. You can enable caching by setting the following properties in the application.properties file.
Şöyle  yaparız
# Maximum time the response should be cached (in seconds)
spring.resources.cache.cachecontrol.max-age=120

# The cache must re-validate stale resources with the server. 
# Any expired resources must not be used without re-validating.
spring.resources.cache.cachecontrol.must-revalidate=true

# The resources are private and intended for a single user. 
# They must not be stored by a shared cache (e.g CDN).
spring.resources.cache.cachecontrol.cache-private= # set a boolean value true/false

# The resources are public and any cache may store the response.
spring.resources.cache.cachecontrol.cache-public= # set a boolean value true/false
tomcat Ayarları
Ağer servlet sunucusu olarak Tomcat kullanıyorsak, Tomcat'a mahsus ayarlar yapılabilir. 
Tomcat Ayarları yazısına taşıdım.

ssl
application.properties SSL Ayarları yazısına taşıdım












Hiç yorum yok:

Yorum Gönder