From 7e3cb50a22eb0e782226d831ec09c223f757f72c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 20 Aug 2013 10:12:52 -0700 Subject: [PATCH] Polish --- .../jdbc/EmbeddedDatabaseConfiguration.java | 33 +++++++++---------- .../web/WebMvcAutoConfiguration.java | 17 +++++----- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConfiguration.java index ffdf504efe..26b9444a83 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConfiguration.java @@ -39,28 +39,25 @@ import org.springframework.util.ClassUtils; public class EmbeddedDatabaseConfiguration { private static final Map EMBEDDED_DATABASE_DRIVER_CLASSES; - private static final Map EMBEDDED_DATABASE_URLS; - - private EmbeddedDatabase database; - static { + Map drivers = new LinkedHashMap(); + drivers.put(EmbeddedDatabaseType.H2, "org.h2.Driver"); + drivers.put(EmbeddedDatabaseType.DERBY, "org.apache.derby.jdbc.EmbeddedDriver"); + drivers.put(EmbeddedDatabaseType.HSQL, "org.hsqldb.jdbcDriver"); + EMBEDDED_DATABASE_DRIVER_CLASSES = drivers; + } - EMBEDDED_DATABASE_DRIVER_CLASSES = new LinkedHashMap(); - EMBEDDED_DATABASE_DRIVER_CLASSES.put(EmbeddedDatabaseType.H2, "org.h2.Driver"); - EMBEDDED_DATABASE_DRIVER_CLASSES.put(EmbeddedDatabaseType.DERBY, - "org.apache.derby.jdbc.EmbeddedDriver"); - EMBEDDED_DATABASE_DRIVER_CLASSES.put(EmbeddedDatabaseType.HSQL, - "org.hsqldb.jdbcDriver"); - - EMBEDDED_DATABASE_URLS = new LinkedHashMap(); - EMBEDDED_DATABASE_URLS.put(EmbeddedDatabaseType.H2, - "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1"); - EMBEDDED_DATABASE_URLS.put(EmbeddedDatabaseType.DERBY, - "jdbc:derby:memory:testdb;create=true"); - EMBEDDED_DATABASE_URLS.put(EmbeddedDatabaseType.HSQL, "jdbc:hsqldb:mem:testdb"); - + private static final Map EMBEDDED_DATABASE_URLS; + static { + Map urls = new LinkedHashMap(); + urls.put(EmbeddedDatabaseType.H2, "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1"); + urls.put(EmbeddedDatabaseType.DERBY, "jdbc:derby:memory:testdb;create=true"); + urls.put(EmbeddedDatabaseType.HSQL, "jdbc:hsqldb:mem:testdb"); + EMBEDDED_DATABASE_URLS = urls; } + private EmbeddedDatabase database; + @Bean public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder() diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index e8221bad16..5af7b06f07 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -98,6 +98,12 @@ public class WebMvcAutoConfiguration { } } + @Bean + @ConditionalOnMissingBean(HiddenHttpMethodFilter.class) + public HiddenHttpMethodFilter hiddenHttpMethodFilter() { + return new HiddenHttpMethodFilter(); + } + // Defined as a nested config to ensure WebMvcConfigurerAdapter it not read when not // on the classpath @EnableWebMvc @@ -111,24 +117,24 @@ public class WebMvcAutoConfiguration { @Autowired private ResourceLoader resourceLoader; + @Bean @ConditionalOnBean(View.class) @ConditionalOnMissingBean(InternalResourceViewResolver.class) - @Bean public InternalResourceViewResolver defaultViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); return resolver; } - @ConditionalOnBean(View.class) @Bean + @ConditionalOnBean(View.class) public BeanNameViewResolver beanNameViewResolver() { BeanNameViewResolver resolver = new BeanNameViewResolver(); resolver.setOrder(0); return resolver; } - @ConditionalOnBean(View.class) @Bean + @ConditionalOnBean(View.class) public ContentNegotiatingViewResolver viewResolver(BeanFactory beanFactory) { ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver(); resolver.setContentNegotiationManager(beanFactory @@ -211,12 +217,7 @@ public class WebMvcAutoConfiguration { return requestHandler; } } - } - @Bean - @ConditionalOnMissingBean(HiddenHttpMethodFilter.class) - public HiddenHttpMethodFilter hiddenHttpMethodFilter() { - return new HiddenHttpMethodFilter(); } }