Is it possible to somehow customize embedded tomcat with RewriteValve? As I can see in api there are currently only methods for addContextValves and addEngineValves but as pointed tomcat in documentation, RewriteValve should be placed in Host or in a webapp's context.xml. I don't understand if addContextValves
could work for this.
Thanks
Conclusion: As explained above, a spring boot project can be deployable in Tomcat. Do remember certain important points as listed: By default, Spring Boot 1.4.4.RELEASE requires Java 7 and Spring Framework 4.3.6.RELEASE or above Higher versions of Tomcat will be helpful to deploy spring-boot applications.
Spring Boot comes with an embedded Tomcat server, which is super-handy. However, we can't see Tomcat's logs by default. In this tutorial, we'll learn how to configure Spring Boot to show Tomcat's internal and access logs via a toy application. 2. Sample Application First of all, let's create a REST API.
These are two steps you need to follow: Implement your own TomcatEmbeddedServletContainerFactory bean and set up the RewriteValve import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; ... import org.apache.catalina.valves.rewrite.RewriteValve; ...
In Spring Boot, we can define the maximum amount of Tomcat worker threads: server.tomcat.threads.max=200. When configuring a web server, it also might be useful to set the server connection timeout. This represents the maximum amount of time the server will wait for the client to make their request after connecting before the connection is closed:
Yes, it is possible. These are two steps you need to follow:
Implement your own TomcatEmbeddedServletContainerFactory bean and set up the RewriteValve
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
...
import org.apache.catalina.valves.rewrite.RewriteValve;
...
@Bean TomcatEmbeddedServletContainerFactory servletContainerFactory() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setPort(8080);
factory.addContextValves(new RewriteValve());
return factory;
}
Add a rewrite.conf file to the WEB-INF directory of your application and specify the rewrite rules. Here is an example rewrite.conf content, which I'm using in the angular application to take advantage of the angular's PathLocationStrategy (basicly I redirect everything to the index.html as we just use spring boot to serve the static web content):
RewriteCond %{REQUEST_URI} !^.*\.(bmp|css|gif|htc|html?|ico|jpe?g|js|pdf|png|swf|txt|xml|svg|eot|woff|woff2|ttf|map)$
RewriteRule ^(.*)$ /index.html [L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With