Skip to content

Instantly share code, notes, and snippets.

@michael-simons
Last active September 7, 2016 08:33
Show Gist options
  • Save michael-simons/74fe5e33f008e086f9ebca0b5c637771 to your computer and use it in GitHub Desktop.
Save michael-simons/74fe5e33f008e086f9ebca0b5c637771 to your computer and use it in GitHub Desktop.
package ac.simons.wjax2016.starter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.spring4.SpringTemplateEngine;
@Configuration
@ConditionalOnClass({SpringTemplateEngine.class, ThymeleafAutoConfiguration.class})
@AutoConfigureBefore(ThymeleafAutoConfiguration.class)
class ThymeleafBannerAutoConfiguration {
}
@michael-simons
Copy link
Author

michael-simons commented Sep 7, 2016

The questions was asked during my talk at Spring I/O 2016 (See: https://www.youtube.com/watch?v=wSWA63rZfGo), wether @AutoConfigureBefore will cause trouble if the auto configuration class in question isn't on the classpath: It depends!

Regarding the ThymeleafAutoConfiguration it won't cause any troubles for projects inherited from Spring Boot Parent, because ThymeleafAutoConfiguration is in there.
But if you depend on another starter, you must shield the application as I did in the 2nd version of the gist, by adding the AutoConfiguration classes to the ConditionalOnClass as well…

@michael-simons
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment