The Tomcat server embedded in Spring Boot runs on port 8080 by default. If we need to modify the Tomcat port, we can configure the Tomcat information in Src/main/resources/application.properties.
- Server. Port=8089
Now, you can rerun the example above to see if the Tomcat port becomes 8089.
If you want to configure Tomcat directly from your code, you can define tomcatembeddedservletcontainerfactory directly.
Now, let's do a little makeover on the example above. First, comment out the configuration information above. Then register the tomcatembeddedservletcontainerfactory with a Bean.
- @Configuration
- Public class tomcatconfig {
- @Bean
- public embeddedservletcontainerfactory servletcontainer() {
- tomcatembeddedservletcontainerfactory tomcatfactory = new Tomcatembeddedservletcontainerfactory();
- Tomcatfactory. Setport(8089);
- return tomcatfactory;
- }
- }
Finish
If you feel that my article is helpful to you, please feel free to make a reward.
- Copyright NOTICE: This article was published by Liang in Liang Blog
- Reprint statement: Free reprint-Non-commercial-non-derivative-maintain attribution (Creative Sharing 3.0 license), non-commercial reprint please indicate the author and source, commercial reprint please contact the author himself.
- Article title: Spring Boot Secrets and Combat (V) Server-Tomcat code configuration
- Article Link: http://blog.720ui.com/2017/springboot_05_server_tomcat_embeddedfactory/
Spring Boot Uncover and Combat (v) Server-Tomcat code configuration