-
What is Hot swapping in spring boot?
Reloading the changes without restarting the server is called hot swapping, Modern IDEs (Eclipse, IDEA, etc.) all support hot swapping of bytecode, so if you make a change that doesn’t affect class or method signatures it should reload cleanly with no side effects.
//不是affect class or method signatures的话, 举个具体的例子
//https://docs.spring.io/spring-boot/docs/current/reference/html/howto-hotswapping.html
Live reloading reloads or refreshes the entire app when a file changes. For example, if you were four links deep into your navigation and saved a change, live reloading would restart the app and load the app back to the initial route.
Hot reloading only refreshes the files that were changed without losing the state of the app. For example, if you were four links deep into your navigation and saved a change to some styling, the state would not change, but the new styles would appear on the page without having to navigate back to the page you are on because you would still be on the same page.
- How do you Switch off the Spring Boot security configuration?
If you define a @Configuration with @EnableWebSecurity anywhere in your application it will switch off the default webapp security settings in Spring Boot.
//有代码举例更好
//需要写一篇博客,不止disable security
-
How to execute Spring Batch jobs on startup?
Spring Batch auto-configuration is enabled by adding @EnableBatchProcessing (from Spring Batch) somewhere in your context. By default it executes all Jobs in the application context on startup
//有代码举例更好,用在哪里,怎么用,可能需要一个github工程
//https://docs.spring.io/spring-boot/docs/current/reference/html/howto-batch-applications.html
//http://spring.io/projects/spring-batch
//http://spring.io/projects/spring-batch#learn
//http://spring.io/guides/gs/batch-processing/
- Does spring boot need Logging? What is the default one?
Spring Boot has no mandatory logging dependency, except for the Commons Logging API.
//如何引入, https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
- How do you configure Configure Logback for logging?
If you put a logback.xml in the root of your classpath it will be picked up from there
// 详细,https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
- How do you Configure Log4j for logging?
Spring Boot supports Log4j 2 for logging configuration if it is on the classpath. If you are using the starters for assembling dependencies that means you have to exclude Logback and then include log4j 2 instead
//详细, https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
//log有必要写blog或者github project
//需要比较一下 logback和log4j吗?怎么include log4并且exclude logback
-
How do you write a Write a JSON REST service in spring boot?
Any Spring @RestController in a Spring Boot application should render JSON response by default as long as Jackson2 is on the classpath
-
How do you Write an XML REST service in spring boot?
If you have the Jackson XML extension (jackson-dataformat-xml) on the classpath, it will be used to render XML responses
//是不是要比较一下两者? github project
- What is the default Multipart File Uploads size in spring boot?
By default Spring Boot configures Spring MVC with a maximum file of 1MB per file and a maximum of 10MB of file data in a single request.
you can configure the values via following application properties :
#http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#common-application-properties #search multipart spring.http.multipart.max-file-size=10MB spring.http.multipart.max-request-size=10MB
Spring Boot采用Servlet 3
javax.servlet.http.Part
API来支持文件上传。默认情况下,Spring Boot配置Spring MVC在单个请求中只处理每个文件最大1Mb,最多10Mb的文件数据。你可以覆盖那些值,也可以设置临时文件存储的位置(比如,存储到/tmp
文件夹下)及传递数据刷新到磁盘的阀值(通过使用MultipartProperties
类暴露的属性)。如果你需要设置文件不受限制,可以设置spring.http.multipart.max-file-size
属性值为-1
。
当你想要接收multipart编码文件数据作为Spring MVC控制器(controller)处理方法中被
@RequestParam
注解的MultipartFile
类型的参数时,multipart支持就非常有用了。
更多详情可参考MultipartAutoConfiguration源码
http://www.mkyong.com/spring-boot/spring-boot-file-upload-example/
https://spring.io/guides/gs/uploading-files/
//,可能需要一个github工程
-
How do you Enable HTTP response compression in spring boot?
HTTP response compression is supported by Jetty, Tomcat, and Undertow. It can be enabled by adding server.compression.enabled=true in application.properties
// server compression 有什么作用?
//以下来自其他博客,需要核实一下
需要在application.properties里启用压缩,并设置压缩支持的格式(默认支持text/html等,但不支持application/json)
server.compression.enabled=true server.compression.mime-types=application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/javascript
默认情况下,仅会压缩2048字节以上的内容
server.compression.min-response-size=2048
还需要在代码中设置如下:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("/static/") .setCacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES).cachePrivate()) .resourceChain(true) .addResolver(new GzipResourceResolver()); super.addResourceHandlers(registry); }
如果在配置文件中配置了不生效,则需要设置上面的内容。
How to check if compression is enabled
- How do you add Add a Servlet, Filter or Listener to an application ?
There are two ways to add Servlet, Filter, ServletContextListener and the other listeners supported by the Servlet spec to your application. You can either provide Spring beans for them, or enable scanning for Servlet components.
//代码实例?
//https://www.boraji.com/spring-boot-using-servlet-filter-and-listener-example-1
//https://www.boraji.com/spring-boot-using-servlet-filter-and-listener-example-2
//http://blog.didispace.com/books/spring-boot-reference/IX.%20%E2%80%98How-to%E2%80%99%20guides/70.1%20Add%20a%20Servlet,%20Filter%20or%20ServletContextListener%20to%20an%20application.html
- How do you Change tomcat or jetty HTTP port?
You can change the tomcat http port by changing default http property in application.properties file.