From b02be6e6ec761d17deebbb5733505bbd20b68d62 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 17 Jul 2013 12:00:58 +0100 Subject: [PATCH] Thymeleaf dialects now handled as @Autowired collection This fixed the immediate problem with Thymeleaf, but leaves open the question of how we can prevent other race conditions developing. As long as the container can start handling requests before the Spring context is refreshed this will be a source of bugs. [Fixes #53482411] [bs-235] Race condition in Thymeleaf --- .../thymeleaf/ThymeleafAutoConfiguration.java | 32 +++++++------------ spring-package-maven-plugin/pom.xml | 2 +- spring-starters/pom.xml | 2 ++ spring-starters/spring-starter-jetty/pom.xml | 25 +++++++++++++++ spring-starters/spring-starter-parent/pom.xml | 5 +++ spring-starters/spring-starter-tomcat/pom.xml | 25 +++++++++++++++ spring-starters/spring-starter-web/pom.xml | 17 +++------- 7 files changed, 75 insertions(+), 33 deletions(-) create mode 100644 spring-starters/spring-starter-jetty/pom.xml create mode 100644 spring-starters/spring-starter-tomcat/pom.xml diff --git a/spring-autoconfigure/src/main/java/org/springframework/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-autoconfigure/src/main/java/org/springframework/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index 08f30070da6..05cab907b5b 100644 --- a/spring-autoconfigure/src/main/java/org/springframework/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-autoconfigure/src/main/java/org/springframework/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -21,7 +21,6 @@ import java.io.InputStream; import java.util.Collection; import java.util.Collections; -import javax.annotation.PostConstruct; import javax.servlet.Servlet; import nz.net.ultraq.thymeleaf.LayoutDialect; @@ -33,12 +32,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.bootstrap.context.condition.ConditionalOnClass; import org.springframework.bootstrap.context.condition.ConditionalOnMissingBean; -import org.springframework.bootstrap.context.condition.ConditionalOnMissingClass; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; import org.thymeleaf.TemplateProcessingParameters; +import org.thymeleaf.dialect.IDialect; import org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect; import org.thymeleaf.resourceresolver.IResourceResolver; import org.thymeleaf.spring3.SpringTemplateEngine; @@ -107,19 +106,24 @@ public class ThymeleafAutoConfiguration { } @Configuration - @ConditionalOnMissingClass("nz.net.ultraq.thymeleaf.LayoutDialect") @ConditionalOnMissingBean(SpringTemplateEngine.class) protected static class ThymeleafDefaultConfiguration { @Autowired private Collection templateResolvers = Collections.emptySet(); + @Autowired(required = false) + private Collection dialects = Collections.emptySet(); + @Bean public SpringTemplateEngine templateEngine() { SpringTemplateEngine engine = new SpringTemplateEngine(); for (ITemplateResolver templateResolver : this.templateResolvers) { engine.addTemplateResolver(templateResolver); } + for (IDialect dialect : this.dialects) { + engine.addDialect(dialect); + } return engine; } @@ -127,20 +131,11 @@ public class ThymeleafAutoConfiguration { @Configuration @ConditionalOnClass(name = "nz.net.ultraq.thymeleaf.LayoutDialect") - @ConditionalOnMissingBean(SpringTemplateEngine.class) protected static class ThymeleafWebLayoutConfiguration { - @Autowired - private Collection templateResolvers = Collections.emptySet(); - @Bean - public SpringTemplateEngine templateEngine() { - SpringTemplateEngine engine = new SpringTemplateEngine(); - for (ITemplateResolver templateResolver : this.templateResolvers) { - engine.addTemplateResolver(templateResolver); - } - engine.addDialect(new LayoutDialect()); - return engine; + public LayoutDialect layoutDialect() { + return new LayoutDialect(); } } @@ -167,12 +162,9 @@ public class ThymeleafAutoConfiguration { @ConditionalOnClass({ SpringSecurityDialect.class }) protected static class ThymeleafSecurityDialectConfiguration { - @Autowired - private SpringTemplateEngine templateEngine; - - @PostConstruct - public void configureThymeleafSecurity() { - this.templateEngine.addDialect(new SpringSecurityDialect()); + @Bean + public SpringSecurityDialect securityDialect() { + return new SpringSecurityDialect(); } } diff --git a/spring-package-maven-plugin/pom.xml b/spring-package-maven-plugin/pom.xml index 300e926e54d..716d7be6ad2 100644 --- a/spring-package-maven-plugin/pom.xml +++ b/spring-package-maven-plugin/pom.xml @@ -99,7 +99,7 @@ maven-plugin-plugin - spring + spring-package diff --git a/spring-starters/pom.xml b/spring-starters/pom.xml index 20fdbeb0c46..05c15652d94 100644 --- a/spring-starters/pom.xml +++ b/spring-starters/pom.xml @@ -18,9 +18,11 @@ spring-starter-batch spring-starter-data-jpa spring-starter-integration + spring-starter-jetty spring-starter-logging spring-starter-parent spring-starter-security + spring-starter-tomcat spring-starter-web diff --git a/spring-starters/spring-starter-jetty/pom.xml b/spring-starters/spring-starter-jetty/pom.xml new file mode 100644 index 00000000000..4d5f067a95e --- /dev/null +++ b/spring-starters/spring-starter-jetty/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + org.springframework.zero + spring-starters + 0.5.0.BUILD-SNAPSHOT + + spring-starter-jetty + jar + + ${basedir}/../.. + + + + org.eclipse.jetty + jetty-webapp + + + org.eclipse.jetty + jetty-jsp + + + diff --git a/spring-starters/spring-starter-parent/pom.xml b/spring-starters/spring-starter-parent/pom.xml index 1b3eb35d2f4..3f9f96f1894 100644 --- a/spring-starters/spring-starter-parent/pom.xml +++ b/spring-starters/spring-starter-parent/pom.xml @@ -56,6 +56,11 @@ spring-starter-tomcat ${spring.zero.version} + + org.springframework.zero + spring-starter-jetty + ${spring.zero.version} + org.springframework.zero spring-starter-data-jpa diff --git a/spring-starters/spring-starter-tomcat/pom.xml b/spring-starters/spring-starter-tomcat/pom.xml new file mode 100644 index 00000000000..fd8b0a1f1ff --- /dev/null +++ b/spring-starters/spring-starter-tomcat/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + org.springframework.zero + spring-starters + 0.5.0.BUILD-SNAPSHOT + + spring-starter-tomcat + jar + + ${basedir}/../.. + + + + org.apache.tomcat.embed + tomcat-embed-core + + + org.apache.tomcat.embed + tomcat-embed-logging-juli + + + diff --git a/spring-starters/spring-starter-web/pom.xml b/spring-starters/spring-starter-web/pom.xml index aa0ab8e8749..22ee2688eb2 100644 --- a/spring-starters/spring-starter-web/pom.xml +++ b/spring-starters/spring-starter-web/pom.xml @@ -19,20 +19,13 @@ ${project.version} - com.fasterxml.jackson.core - jackson-databind - - - javax.servlet - javax.servlet-api - - - org.apache.tomcat.embed - tomcat-embed-core + ${project.groupId} + spring-starter-tomcat + ${project.version} - org.apache.tomcat.embed - tomcat-embed-logging-juli + com.fasterxml.jackson.core + jackson-databind org.springframework