Spring Boot Security + Thymeleaf : IProcessorDialect class missing
<p>I'm trying to integrate the Thymeleaf security dialect (such as <em>sec:authorize</em> tag) into a Spring Boot + Spring Security application that is working properly.</p>

<p>After some research I found that the solution to activate that is to:</p>

<p>Add the dependency in the POM file:</p>

<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.thymeleaf.extras&lt;/groupId&gt;
    &lt;artifactId&gt;thymeleaf-extras-springsecurity4&lt;/artifactId&gt;
    &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>

<p>and include the tag at the top of the template file:</p>

<pre><code>&lt;html   xmlns:th="http://www.thymeleaf.org" lang="en"
        xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"&gt;
</code></pre>

<p>So far, so good. Dependency is found, the tags recognized in the markup.</p>

<p><strong>However they're not taken into account and appear in the final HTML generated.</strong></p>

<p>Because of a problem in the Spring Boot auto-configuration which doesn't enable, it seems to be necessary to manually add a <strong>SpringSecurityDialect</strong> Bean to one @Configuration class to enable it (several questions found on StackOverflow have been solved by this):</p>

<pre><code>@Bean
    public SpringSecurityDialect securityDialect() {
        return new SpringSecurityDialect();
    }
</code></pre>

<p>This is what causes a problem: when I add this Bean into my Spring Boot Configuration, it raises an Exception because it can't find the class <strong>org.thymeleaf.dialect.IProcessorDialect</strong>. Here is the error:</p>

<pre><code>&gt; java.lang.IllegalStateException: Could not evaluate condition on
&gt; org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
&gt; due to org/thymeleaf/dialect/IProcessorDialect not found. Make sure
&gt; your own configuration does not rely on that class. This can also
&gt; happen if you are @ComponentScanning a springframework package (e.g.
&gt; if you put a @ComponentScan in the default package by mistake)
</code></pre>

<p><strong>What am I missing? Is this an error coming from Thymeleaf? Spring Boot? My own code? Thanks in advance for your help !</strong></p>

<p>Here are some of my files concerned by my issue:</p>

<p><em>Application.java</em></p>

<pre><code>@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
      public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
            @Override
            protected void postProcessContext(Context context) {
              SecurityConstraint securityConstraint = new SecurityConstraint();
              securityConstraint.setUserConstraint("CONFIDENTIAL");
              SecurityCollection collection = new SecurityCollection();
              collection.addPattern("/*");
              securityConstraint.addCollection(collection);
              context.addConstraint(securityConstraint);
            }
          };

        tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
        return tomcat;
      }

      private Connector initiateHttpConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(8443);

        return connector;
      }
}
</code></pre>

<p><em>WebMvcConfig.java</em></p>

<pre><code>import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    /**
     * Configure relationships between URLs and view names
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
    }

    @Bean
    public SpringSecurityDialect securityDialect() {
        return new SpringSecurityDialect();
    }
}
</code></pre>

<p><em>Thymeleaf template:</em></p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html   xmlns:th="http://www.thymeleaf.org" lang="en"
        xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"&gt;

....

&lt;div sec:authorize="isAuthenticated()"&gt;
    LOGGED IN
&lt;/div&gt;
&lt;div sec:authorize="isAnonymous()"&gt;
    ANONYMOUS
&lt;/div&gt;

....
</code></pre>

<p><em>The full console output when starting the application:</em></p>

<pre><code>&gt;  :: Spring Boot ::        (v1.3.4.RELEASE)
&gt; 
&gt; 2016-05-17 17:22:59.951  INFO 96267 --- [  restartedMain]
&gt; edu.rmit.eres.estored.Application        : Starting Application on
&gt; w8031808.local with PID 96267
&gt; (/Users/guillaume/dev/workspace/e-stored/target/classes started by
&gt; guillaume in /Users/guillaume/dev/workspace/e-stored) 2016-05-17
&gt; 17:22:59.956  INFO 96267 --- [  restartedMain]
&gt; edu.rmit.eres.estored.Application        : No active profile set,
&gt; falling back to default profiles: default 2016-05-17 17:23:00.239 
&gt; INFO 96267 --- [  restartedMain]
&gt; ationConfigEmbeddedWebApplicationContext : Refreshing
&gt; org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@16f53cde:
&gt; startup date [Tue May 17 17:23:00 AEST 2016]; root of context
&gt; hierarchy 2016-05-17 17:23:01.578 ERROR 96267 --- [  restartedMain]
&gt; o.s.boot.SpringApplication               : Application startup failed
&gt; 
&gt; java.lang.IllegalStateException: Could not evaluate condition on
&gt; org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
&gt; due to org/thymeleaf/dialect/IProcessorDialect not found. Make sure
&gt; your own configuration does not rely on that class. This can also
&gt; happen if you are @ComponentScanning a springframework package (e.g.
&gt; if you put a @ComponentScan in the default package by mistake)    at
&gt; org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:55)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
&gt; org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:178)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:140)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:333)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
&gt; ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
&gt; org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
&gt; ~[spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]    at
&gt; org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
&gt; [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
&gt; org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
&gt; [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
&gt; org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
&gt; [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
&gt; org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
&gt; [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
&gt; org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
&gt; [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
&gt; edu.rmit.eres.estored.Application.main(Application.java:24)
&gt; [classes/:na]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
&gt; Method) ~[na:1.8.0_60]    at
&gt; sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
&gt; ~[na:1.8.0_60]    at
&gt; sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
&gt; ~[na:1.8.0_60]    at java.lang.reflect.Method.invoke(Method.java:497)
&gt; ~[na:1.8.0_60]    at
&gt; org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
&gt; [spring-boot-devtools-1.3.4.RELEASE.jar:1.3.4.RELEASE] Caused by:
&gt; java.lang.NoClassDefFoundError:
&gt; org/thymeleaf/dialect/IProcessorDialect   at
&gt; java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_60]  at
&gt; java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_60]
&gt;   at
&gt; java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
&gt; ~[na:1.8.0_60]    at
&gt; java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
&gt; ~[na:1.8.0_60]    at
&gt; java.net.URLClassLoader.access$100(URLClassLoader.java:73)
&gt; ~[na:1.8.0_60]    at
&gt; java.net.URLClassLoader$1.run(URLClassLoader.java:368) ~[na:1.8.0_60]
&gt;   at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
&gt; ~[na:1.8.0_60]    at java.security.AccessController.doPrivileged(Native
&gt; Method) ~[na:1.8.0_60]    at
&gt; java.net.URLClassLoader.findClass(URLClassLoader.java:361)
&gt; ~[na:1.8.0_60]    at
&gt; java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
&gt;   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
&gt; ~[na:1.8.0_60]    at
&gt; java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
&gt;   at
&gt; org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:151)
&gt; ~[spring-boot-devtools-1.3.4.RELEASE.jar:1.3.4.RELEASE]   at
&gt; java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
&gt;   at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_60]
&gt;   at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
&gt; ~[na:1.8.0_60]    at java.lang.Class.getDeclaredMethods(Class.java:1975)
&gt; ~[na:1.8.0_60]    at
&gt; org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:612)
&gt; ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]    at
&gt; org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
&gt; ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]    at
&gt; org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
&gt; ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]    at
&gt; org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:570)
&gt; ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]    at
&gt; org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:683)
&gt; ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
&gt; org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:627)
&gt; ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
&gt; org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597)
&gt; ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
&gt; org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1445)
&gt; ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
&gt; org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:975)
&gt; ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
&gt; org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:289)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
&gt; org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.addBeanType(BeanTypeRegistry.java:278)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
&gt; org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.getNamesForType(BeanTypeRegistry.java:259)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
&gt; org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:182)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
&gt; org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:171)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
&gt; org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:139)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
&gt; org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:113)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
&gt; org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
&gt; ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  ... 22
&gt; common frames omitted Caused by: java.lang.ClassNotFoundException:
&gt; org.thymeleaf.dialect.IProcessorDialect   at
&gt; java.net.URLClassLoader.findClass(URLClassLoader.java:381)
&gt; ~[na:1.8.0_60]    at
&gt; java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
&gt;   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
&gt; ~[na:1.8.0_60]    at
&gt; java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
&gt;   ... 56 common frames omitted
&gt; 
&gt; 2016-05-17 17:23:01.581  INFO 96267 --- [  restartedMain]
&gt; .b.l.ClasspathLoggingApplicationListener : Application failed to start
&gt; with classpath:
&gt; [file:/Users/guillaume/dev/workspace/e-stored/target/classes/]
</code></pre>