Spring Redirecting from Http to Https Breaks Rest Controller Test

1.2k Views Asked by At

I'm redirecting from http to https using the TomcatEmbeddedServletContainerFactory instructions found here:

http://drissamri.be/blog/java/enable-https-in-spring-boot/

However this breaks the testing of the rest controller, even though it uses an Application to run the test that does not contain or reference the TomcatEmbeddedServletContainerFactory configuration performing the redirection.

If I remove the redirection configuration from the Application that contains the @SpringBootApplication annotation that runs the application, the test passes.

Any idea how to keep the production configuration for the application in place without breaking the Rest controller configuration?

TIA, - Ole

1

There are 1 best solutions below

2
On

If you don't want to use the TomcatEmbeddedServletContainerFactory in your Application.java in your test, you could always add work with Spring profiles to make sure that bean is only loaded when you start your application with a certain profile (production for example).

Then the @Bean TomcatEmbeddedServletContainerFactory would have a @Profile("production") annotation, and your test would not create that bean unless you are using the production profile explicitly.

I will update this answer when you give more information regarding your problem.