Commit e891aa35 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 93aefa85
...@@ -81,14 +81,12 @@ import org.springframework.util.StringUtils; ...@@ -81,14 +81,12 @@ import org.springframework.util.StringUtils;
* into a Spring Boot enabled application. By default a SSH daemon is started on port * into a Spring Boot enabled application. By default a SSH daemon is started on port
* 2000. If the CRaSH Telnet plugin is available on the classpath, Telnet daemon will be * 2000. If the CRaSH Telnet plugin is available on the classpath, Telnet daemon will be
* launched on port 5000. * launched on port 5000.
*
* <p> * <p>
* The default shell authentication method uses a username and password combination. If no * The default shell authentication method uses a username and password combination. If no
* configuration is provided the default username is 'user' and the password will be * configuration is provided the default username is 'user' and the password will be
* printed to console during application startup. Those default values can be overridden * printed to console during application startup. Those default values can be overridden
* by using <code>shell.auth.simple.username</code> and * by using <code>shell.auth.simple.username</code> and
* <code>shell.auth.simple.password</code>. * <code>shell.auth.simple.password</code>.
*
* <p> * <p>
* If a Spring Security {@link AuthenticationManager} is detected, this configuration will * If a Spring Security {@link AuthenticationManager} is detected, this configuration will
* create a {@link CRaSHPlugin} to forward shell authentication requests to Spring * create a {@link CRaSHPlugin} to forward shell authentication requests to Spring
...@@ -98,14 +96,12 @@ import org.springframework.util.StringUtils; ...@@ -98,14 +96,12 @@ import org.springframework.util.StringUtils;
* restricted to users having roles that match those configured in * restricted to users having roles that match those configured in
* {@link ManagementServerProperties}. Required roles can be overridden by * {@link ManagementServerProperties}. Required roles can be overridden by
* <code>shell.auth.spring.roles</code>. * <code>shell.auth.spring.roles</code>.
*
* <p> * <p>
* To add customizations to the shell simply define beans of type {@link CRaSHPlugin} in * To add customizations to the shell simply define beans of type {@link CRaSHPlugin} in
* the application context. Those beans will get auto detected during startup and * the application context. Those beans will get auto detected during startup and
* registered with the underlying shell infrastructure. To configure plugins and the CRaSH * registered with the underlying shell infrastructure. To configure plugins and the CRaSH
* infrastructure add beans of type {@link CrshShellProperties} to the application * infrastructure add beans of type {@link CrshShellProperties} to the application
* context. * context.
*
* <p> * <p>
* Additional shell commands can be implemented using the guide and documentation at <a * Additional shell commands can be implemented using the guide and documentation at <a
* href="http://www.crashub.org">crashub.org</a>. By default Boot will search for commands * href="http://www.crashub.org">crashub.org</a>. By default Boot will search for commands
......
...@@ -48,7 +48,7 @@ public abstract class AutoConfigurationPackages { ...@@ -48,7 +48,7 @@ public abstract class AutoConfigurationPackages {
/** /**
* Determine if the auto-configuration base packages for the given bean factory are * Determine if the auto-configuration base packages for the given bean factory are
* available * available.
* @param beanFactory the source bean factory * @param beanFactory the source bean factory
* @return true if there are auto-config packages available * @return true if there are auto-config packages available
*/ */
......
/* /*
On * Copyright 2012-2014 the original author or authors. * Copyright 2012-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -54,17 +54,19 @@ public class ElasticsearchAutoConfiguration implements DisposableBean { ...@@ -54,17 +54,19 @@ public class ElasticsearchAutoConfiguration implements DisposableBean {
@Bean @Bean
public Client elasticsearchClient() { public Client elasticsearchClient() {
try { try {
if (StringUtils.hasLength(this.properties.getClusterNodes())) { this.client = createClient();
this.client = createTransportClient(); return this.client;
}
else {
this.client = createNodeClient();
}
} }
catch (Exception ex) { catch (Exception ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
} }
return this.client; }
private Client createClient() throws Exception {
if (StringUtils.hasLength(this.properties.getClusterNodes())) {
return createTransportClient();
}
return createNodeClient();
} }
private Client createNodeClient() throws Exception { private Client createNodeClient() throws Exception {
......
/* /*
* Copyright 2014 the original author or authors. * Copyright 2012-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -32,7 +32,7 @@ import org.springframework.integration.jmx.config.IntegrationMBeanExportConfigur ...@@ -32,7 +32,7 @@ import org.springframework.integration.jmx.config.IntegrationMBeanExportConfigur
* *
* @author Artem Bilan * @author Artem Bilan
* @author Dave Syer * @author Dave Syer
* @since 1.1 * @since 1.1.0
*/ */
@Configuration @Configuration
@ConditionalOnClass(EnableIntegration.class) @ConditionalOnClass(EnableIntegration.class)
......
...@@ -65,31 +65,27 @@ public class JacksonAutoConfiguration { ...@@ -65,31 +65,27 @@ public class JacksonAutoConfiguration {
private ListableBeanFactory beanFactory; private ListableBeanFactory beanFactory;
@Bean @Bean
@ConditionalOnMissingBean
@Primary @Primary
@ConditionalOnMissingBean
public ObjectMapper jacksonObjectMapper() { public ObjectMapper jacksonObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
if (this.properties.isJsonSortKeys()) { if (this.properties.isJsonSortKeys()) {
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
} }
return objectMapper; return objectMapper;
} }
@PostConstruct @PostConstruct
public void init() { private void registerModulesWithObjectMappers() {
Collection<Module> modules = getBeans(Module.class);
for (ObjectMapper objectMapper : getBeans(ObjectMapper.class)) {
objectMapper.registerModules(modules);
}
}
Collection<ObjectMapper> mappers = BeanFactoryUtils private <T> Collection<T> getBeans(Class<T> type) {
.beansOfTypeIncludingAncestors(this.beanFactory, ObjectMapper.class) return BeanFactoryUtils.beansOfTypeIncludingAncestors(this.beanFactory, type)
.values(); .values();
Collection<Module> modules = BeanFactoryUtils.beansOfTypeIncludingAncestors(
this.beanFactory, Module.class).values();
for (ObjectMapper mapper : mappers) {
mapper.registerModules(modules);
}
} }
@Configuration @Configuration
...@@ -101,6 +97,7 @@ public class JacksonAutoConfiguration { ...@@ -101,6 +97,7 @@ public class JacksonAutoConfiguration {
JodaModule jacksonJodaModule() { JodaModule jacksonJodaModule() {
return new JodaModule(); return new JodaModule();
} }
} }
@Configuration @Configuration
...@@ -113,5 +110,6 @@ public class JacksonAutoConfiguration { ...@@ -113,5 +110,6 @@ public class JacksonAutoConfiguration {
JSR310Module jacksonJsr310Module() { JSR310Module jacksonJsr310Module() {
return new JSR310Module(); return new JSR310Module();
} }
} }
} }
...@@ -53,9 +53,9 @@ import org.springframework.util.ClassUtils; ...@@ -53,9 +53,9 @@ import org.springframework.util.ClassUtils;
/** /**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} to integrate with an HornetQ broker. If the necessary * Auto-configuration} to integrate with an HornetQ broker. If the necessary classes are
* classes are present, embed the broker in the application by default. Otherwise, * present, embed the broker in the application by default. Otherwise, connect to a broker
* connect to a broker available on the local machine with the default settings. * available on the local machine with the default settings.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 1.1.0 * @since 1.1.0
......
...@@ -58,6 +58,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -58,6 +58,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@Import(DataSourceInitializedPublisher.Registrar.class) @Import(DataSourceInitializedPublisher.Registrar.class)
public abstract class JpaBaseConfiguration implements BeanFactoryAware { public abstract class JpaBaseConfiguration implements BeanFactoryAware {
private static final String[] NO_PACKAGES = new String[0];
private ConfigurableListableBeanFactory beanFactory; private ConfigurableListableBeanFactory beanFactory;
@Autowired @Autowired
...@@ -118,7 +120,7 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware { ...@@ -118,7 +120,7 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
List<String> basePackages = AutoConfigurationPackages.get(this.beanFactory); List<String> basePackages = AutoConfigurationPackages.get(this.beanFactory);
return basePackages.toArray(new String[basePackages.size()]); return basePackages.toArray(new String[basePackages.size()]);
} }
return new String[0]; return NO_PACKAGES;
} }
protected void configure( protected void configure(
......
...@@ -75,5 +75,7 @@ public class HttpMessageConvertersAutoConfiguration { ...@@ -75,5 +75,7 @@ public class HttpMessageConvertersAutoConfiguration {
converter.setPrettyPrint(this.properties.isJsonPrettyPrint()); converter.setPrettyPrint(this.properties.isJsonPrettyPrint());
return converter; return converter;
} }
} }
} }
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.batch; package org.springframework.boot.autoconfigure.batch;
import static org.junit.Assert.assertEquals;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.batch.core.Job; import org.springframework.batch.core.Job;
...@@ -46,6 +44,8 @@ import org.springframework.context.annotation.Configuration; ...@@ -46,6 +44,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SyncTaskExecutor; import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import static org.junit.Assert.assertEquals;
/** /**
* Tests for {@link JobLauncherCommandLineRunner}. * Tests for {@link JobLauncherCommandLineRunner}.
* *
......
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
package org.springframework.boot.autoconfigure.jackson; package org.springframework.boot.autoconfigure.jackson;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Map;
import org.hamcrest.Matchers;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
...@@ -40,6 +39,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; ...@@ -40,6 +39,7 @@ import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.joda.JodaModule; import com.fasterxml.jackson.datatype.joda.JodaModule;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
...@@ -72,27 +72,20 @@ public class JacksonAutoConfigurationTests { ...@@ -72,27 +72,20 @@ public class JacksonAutoConfigurationTests {
@Test @Test
public void registersJodaModuleAutomatically() { public void registersJodaModuleAutomatically() {
this.context.register(JacksonAutoConfiguration.class); this.context.register(JacksonAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
Map<String, Module> modules = this.context.getBeansOfType(Module.class);
Collection<Module> modules = this.context.getBeansOfType(Module.class).values(); assertThat(modules.size(), greaterThanOrEqualTo(1)); // Depends on the JDK
assertThat(modules, is(Matchers.<Module> iterableWithSize(1))); assertThat(modules.get("jacksonJodaModule"), is(instanceOf(JodaModule.class)));
assertThat(modules.iterator().next(), is(instanceOf(JodaModule.class)));
ObjectMapper objectMapper = this.context.getBean(ObjectMapper.class); ObjectMapper objectMapper = this.context.getBean(ObjectMapper.class);
assertThat(objectMapper.canSerialize(LocalDateTime.class), is(true)); assertThat(objectMapper.canSerialize(LocalDateTime.class), is(true));
} }
@Test @Test
public void customJacksonModules() throws Exception { public void customJacksonModules() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(ModulesConfig.class, JacksonAutoConfiguration.class); this.context.register(ModulesConfig.class, JacksonAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class); ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
@SuppressWarnings({ "unchecked", "unused" }) @SuppressWarnings({ "unchecked", "unused" })
ObjectMapper result = verify(mapper).registerModules( ObjectMapper result = verify(mapper).registerModules(
(Iterable<Module>) argThat(hasItem(this.context.getBean("jacksonModule", (Iterable<Module>) argThat(hasItem(this.context.getBean("jacksonModule",
...@@ -101,12 +94,9 @@ public class JacksonAutoConfigurationTests { ...@@ -101,12 +94,9 @@ public class JacksonAutoConfigurationTests {
@Test @Test
public void doubleModuleRegistration() throws Exception { public void doubleModuleRegistration() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(DoubleModulesConfig.class, this.context.register(DoubleModulesConfig.class,
HttpMessageConvertersAutoConfiguration.class); HttpMessageConvertersAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class); ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertEquals("{\"foo\":\"bar\"}", mapper.writeValueAsString(new Foo())); assertEquals("{\"foo\":\"bar\"}", mapper.writeValueAsString(new Foo()));
} }
...@@ -124,6 +114,7 @@ public class JacksonAutoConfigurationTests { ...@@ -124,6 +114,7 @@ public class JacksonAutoConfigurationTests {
public ObjectMapper objectMapper() { public ObjectMapper objectMapper() {
return Mockito.mock(ObjectMapper.class); return Mockito.mock(ObjectMapper.class);
} }
} }
@Configuration @Configuration
...@@ -153,6 +144,7 @@ public class JacksonAutoConfigurationTests { ...@@ -153,6 +144,7 @@ public class JacksonAutoConfigurationTests {
mapper.registerModule(jacksonModule()); mapper.registerModule(jacksonModule());
return mapper; return mapper;
} }
} }
protected static class Foo { protected static class Foo {
...@@ -160,7 +152,6 @@ public class JacksonAutoConfigurationTests { ...@@ -160,7 +152,6 @@ public class JacksonAutoConfigurationTests {
private String name; private String name;
private Foo() { private Foo() {
} }
static Foo create() { static Foo create() {
...@@ -176,4 +167,5 @@ public class JacksonAutoConfigurationTests { ...@@ -176,4 +167,5 @@ public class JacksonAutoConfigurationTests {
} }
} }
} }
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
package org.springframework.boot.autoconfigure.orm.jpa; package org.springframework.boot.autoconfigure.orm.jpa;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.junit.After; import org.junit.After;
...@@ -34,6 +29,10 @@ import org.springframework.boot.test.EnvironmentTestUtils; ...@@ -34,6 +29,10 @@ import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link HibernateJpaAutoConfiguration}. * Tests for {@link HibernateJpaAutoConfiguration}.
* *
...@@ -66,7 +65,7 @@ public class CustomHibernateJpaAutoConfigurationTests { ...@@ -66,7 +65,7 @@ public class CustomHibernateJpaAutoConfigurationTests {
String actual = bean.getHibernateProperties(dataSource).get( String actual = bean.getHibernateProperties(dataSource).get(
"hibernate.hbm2ddl.auto"); "hibernate.hbm2ddl.auto");
// Default is generic and safe // Default is generic and safe
assertThat(actual, is(nullValue())); assertThat(actual, nullValue());
} }
@Test @Test
......
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.reactor; package org.springframework.boot.autoconfigure.reactor;
import static org.junit.Assert.assertNotNull;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -27,7 +25,11 @@ import reactor.core.Environment; ...@@ -27,7 +25,11 @@ import reactor.core.Environment;
import reactor.core.Reactor; import reactor.core.Reactor;
import reactor.core.spec.Reactors; import reactor.core.spec.Reactors;
import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link ReactorAutoConfiguration}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class ReactorAutoConfigurationTests { public class ReactorAutoConfigurationTests {
......
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.security.jpa; package org.springframework.boot.autoconfigure.security.jpa;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.user.SecurityConfig;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/** /**
...@@ -13,11 +36,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -13,11 +36,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* their instantiation order was accelerated by Security). * their instantiation order was accelerated by Security).
* *
* @author Dave Syer * @author Dave Syer
*
* @since 1.1
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Main.class) @SpringApplicationConfiguration(classes = JpaUserDetailsTests.Main.class)
public class JpaUserDetailsTests { public class JpaUserDetailsTests {
@Test @Test
...@@ -28,4 +49,10 @@ public class JpaUserDetailsTests { ...@@ -28,4 +49,10 @@ public class JpaUserDetailsTests {
SpringApplication.run(Main.class, args); SpringApplication.run(Main.class, args);
} }
@Import({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, SecurityAutoConfiguration.class })
@ComponentScan(basePackageClasses = SecurityConfig.class)
public static class Main {
}
} }
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.security.jpa;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.user.SecurityConfig;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
@Import({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, SecurityAutoConfiguration.class })
@ComponentScan(basePackageClasses = SecurityConfig.class)
public class Main {
}
\ No newline at end of file
package org.springframework.boot.autoconfigure.security.user; package org.springframework.boot.autoconfigure.security.user;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.security.user; package org.springframework.boot.autoconfigure.security.user;
import javax.persistence.Entity; import javax.persistence.Entity;
...@@ -6,9 +22,11 @@ import javax.persistence.Id; ...@@ -6,9 +22,11 @@ import javax.persistence.Id;
@Entity @Entity
public class User { public class User {
@Id @Id
@GeneratedValue @GeneratedValue
private Long id; private Long id;
private String email; private String email;
public User() { public User() {
...@@ -19,7 +37,7 @@ public class User { ...@@ -19,7 +37,7 @@ public class User {
} }
public Long getId() { public Long getId() {
return id; return this.id;
} }
public void setId(Long id) { public void setId(Long id) {
...@@ -27,14 +45,16 @@ public class User { ...@@ -27,14 +45,16 @@ public class User {
} }
public String getEmail() { public String getEmail() {
return email; return this.email;
} }
public void setEmail(String email) { public void setEmail(String email) {
this.email = email; this.email = email;
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + ":" + id; return getClass().getSimpleName() + ":" + this.id;
} }
} }
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.security.user; package org.springframework.boot.autoconfigure.security.user;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Integer> { public interface UserRepository extends JpaRepository<User, Integer> {
public User findByEmail(String email); public User findByEmail(String email);
} }
...@@ -36,7 +36,7 @@ import static org.junit.Assert.assertTrue; ...@@ -36,7 +36,7 @@ import static org.junit.Assert.assertTrue;
*/ */
public class HttpMessageConvertersAutoConfigurationTests { public class HttpMessageConvertersAutoConfigurationTests {
private AnnotationConfigApplicationContext context; private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();;
@After @After
public void close() { public void close() {
...@@ -47,17 +47,13 @@ public class HttpMessageConvertersAutoConfigurationTests { ...@@ -47,17 +47,13 @@ public class HttpMessageConvertersAutoConfigurationTests {
@Test @Test
public void customJacksonConverter() throws Exception { public void customJacksonConverter() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(JacksonConfig.class, this.context.register(JacksonConfig.class,
HttpMessageConvertersAutoConfiguration.class); HttpMessageConvertersAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
MappingJackson2HttpMessageConverter converter = this.context MappingJackson2HttpMessageConverter converter = this.context
.getBean(MappingJackson2HttpMessageConverter.class); .getBean(MappingJackson2HttpMessageConverter.class);
assertEquals(this.context.getBean(ObjectMapper.class), assertEquals(this.context.getBean(ObjectMapper.class),
converter.getObjectMapper()); converter.getObjectMapper());
HttpMessageConverters converters = this.context HttpMessageConverters converters = this.context
.getBean(HttpMessageConverters.class); .getBean(HttpMessageConverters.class);
assertTrue(converters.getConverters().contains(converter)); assertTrue(converters.getConverters().contains(converter));
...@@ -77,5 +73,7 @@ public class HttpMessageConvertersAutoConfigurationTests { ...@@ -77,5 +73,7 @@ public class HttpMessageConvertersAutoConfigurationTests {
public ObjectMapper objectMapper() { public ObjectMapper objectMapper() {
return new ObjectMapper(); return new ObjectMapper();
} }
} }
} }
...@@ -319,7 +319,7 @@ public class WebMvcAutoConfigurationTests { ...@@ -319,7 +319,7 @@ public class WebMvcAutoConfigurationTests {
} }
@Configuration @Configuration
protected static class Config { public static class Config {
@Bean @Bean
public EmbeddedServletContainerFactory containerFactory() { public EmbeddedServletContainerFactory containerFactory() {
......
...@@ -33,4 +33,3 @@ databaseChangeLog: ...@@ -33,4 +33,3 @@ databaseChangeLog:
type: varchar(50) type: varchar(50)
constraints: constraints:
nullable: true nullable: true
\ No newline at end of file
...@@ -9,4 +9,5 @@ class Sample implements CommandLineRunner { ...@@ -9,4 +9,5 @@ class Sample implements CommandLineRunner {
void run(String... args) { void run(String... args) {
println "Hello World" println "Hello World"
} }
} }
...@@ -21,7 +21,6 @@ import org.gradle.api.Project ...@@ -21,7 +21,6 @@ import org.gradle.api.Project
import org.gradle.api.plugins.ApplicationPlugin import org.gradle.api.plugins.ApplicationPlugin
import org.gradle.api.plugins.BasePlugin import org.gradle.api.plugins.BasePlugin
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.compile.Compile
import org.springframework.boot.gradle.agent.AgentPluginFeatures import org.springframework.boot.gradle.agent.AgentPluginFeatures
import org.springframework.boot.gradle.repackage.RepackagePluginFeatures import org.springframework.boot.gradle.repackage.RepackagePluginFeatures
import org.springframework.boot.gradle.resolve.ResolvePluginFeatures import org.springframework.boot.gradle.resolve.ResolvePluginFeatures
...@@ -48,11 +47,14 @@ class SpringBootPlugin implements Plugin<Project> { ...@@ -48,11 +47,14 @@ class SpringBootPlugin implements Plugin<Project> {
new RepackagePluginFeatures().apply(project) new RepackagePluginFeatures().apply(project)
new RunPluginFeatures().apply(project) new RunPluginFeatures().apply(project)
// default to UTF-8 encoding useUtf8Encoding(project)
project.tasks.withType(Compile).all { t-> }
t.doFirst {
if(!t.options.encoding) { private useUtf8Encoding(Project project) {
t.options.encoding = 'UTF-8' project.tasks.withType(org.gradle.api.tasks.compile.Compile).all {
it.doFirst {
if(!it.options.encoding) {
it.options.encoding = 'UTF-8'
} }
} }
} }
......
...@@ -383,10 +383,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc ...@@ -383,10 +383,6 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
/** /**
* Convenience class to flatten out a tree of property sources without losing the * Convenience class to flatten out a tree of property sources without losing the
* reference to the backing data (which can therefore be updated in the background). * reference to the backing data (which can therefore be updated in the background).
*
* @param propertySources some PropertySources, possibly containing environment
* properties
* @return another PropertySources containing the same properties
*/ */
private static class FlatPropertySources implements PropertySources { private static class FlatPropertySources implements PropertySources {
...@@ -414,7 +410,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc ...@@ -414,7 +410,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
private MutablePropertySources getFlattened() { private MutablePropertySources getFlattened() {
MutablePropertySources result = new MutablePropertySources(); MutablePropertySources result = new MutablePropertySources();
for (PropertySource<?> propertySource : propertySources) { for (PropertySource<?> propertySource : this.propertySources) {
flattenPropertySources(propertySource, result); flattenPropertySources(propertySource, result);
} }
return result; return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment