diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java index af55f05b8d..7d72a2fd2d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java @@ -46,7 +46,6 @@ import org.springframework.core.annotation.AliasFor; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@AutoConfigurationPackage @Import(ImportAutoConfigurationImportSelector.class) public @interface ImportAutoConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java index adb08088f3..6bb3959619 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java @@ -49,8 +49,8 @@ class ActiveMQConnectionFactoryConfiguration { public ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties, ObjectProvider> factoryCustomizers) { return new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.getIfAvailable()).createConnectionFactory( - ActiveMQConnectionFactory.class); + factoryCustomizers.getIfAvailable()) + .createConnectionFactory(ActiveMQConnectionFactory.class); } @ConditionalOnClass(PooledConnectionFactory.class) @@ -67,21 +67,21 @@ class ActiveMQConnectionFactoryConfiguration { ActiveMQConnectionFactory.class)); ActiveMQProperties.Pool pool = properties.getPool(); pooledConnectionFactory.setBlockIfSessionPoolIsFull(pool.isBlockIfFull()); - pooledConnectionFactory.setBlockIfSessionPoolIsFullTimeout( - pool.getBlockIfFullTimeout()); - pooledConnectionFactory.setCreateConnectionOnStartup( - pool.isCreateConnectionOnStartup()); + pooledConnectionFactory + .setBlockIfSessionPoolIsFullTimeout(pool.getBlockIfFullTimeout()); + pooledConnectionFactory + .setCreateConnectionOnStartup(pool.isCreateConnectionOnStartup()); pooledConnectionFactory.setExpiryTimeout(pool.getExpiryTimeout()); pooledConnectionFactory.setIdleTimeout(pool.getIdleTimeout()); pooledConnectionFactory.setMaxConnections(pool.getMaxConnections()); pooledConnectionFactory.setMaximumActiveSessionPerConnection( pool.getMaximumActiveSessionPerConnection()); - pooledConnectionFactory.setReconnectOnException( - pool.isReconnectOnException()); + pooledConnectionFactory + .setReconnectOnException(pool.isReconnectOnException()); pooledConnectionFactory.setTimeBetweenExpirationCheckMillis( pool.getTimeBetweenExpirationCheck()); - pooledConnectionFactory.setUseAnonymousProducers( - pool.isUseAnonymousProducers()); + pooledConnectionFactory + .setUseAnonymousProducers(pool.isUseAnonymousProducers()); return pooledConnectionFactory; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java index 3948139ed8..e98b615754 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java @@ -158,8 +158,8 @@ public class ActiveMQProperties { private boolean blockIfFull = true; /** - * Blocking period, in milliseconds, before throwing an exception if the pool - * is still full. + * Blocking period, in milliseconds, before throwing an exception if the pool is + * still full. */ private long blockIfFullTimeout = -1; @@ -265,7 +265,8 @@ public class ActiveMQProperties { return this.maximumActiveSessionPerConnection; } - public void setMaximumActiveSessionPerConnection(int maximumActiveSessionPerConnection) { + public void setMaximumActiveSessionPerConnection( + int maximumActiveSessionPerConnection) { this.maximumActiveSessionPerConnection = maximumActiveSessionPerConnection; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java index e12a51a554..84f65f44ef 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java @@ -54,7 +54,7 @@ class ActiveMQXAConnectionFactoryConfiguration { XAConnectionFactoryWrapper wrapper) throws Exception { ActiveMQXAConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory( properties, factoryCustomizers.getIfAvailable()) - .createConnectionFactory(ActiveMQXAConnectionFactory.class); + .createConnectionFactory(ActiveMQXAConnectionFactory.class); return wrapper.wrapConnectionFactory(connectionFactory); } @@ -64,8 +64,8 @@ class ActiveMQXAConnectionFactoryConfiguration { ActiveMQProperties properties, ObjectProvider> factoryCustomizers) { return new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.getIfAvailable()).createConnectionFactory( - ActiveMQConnectionFactory.class); + factoryCustomizers.getIfAvailable()) + .createConnectionFactory(ActiveMQConnectionFactory.class); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java index 3dfc9183b4..3c1d17980c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java @@ -37,6 +37,7 @@ import org.springframework.core.env.Environment; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; +import org.springframework.util.ClassUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verifyZeroInteractions; @@ -125,7 +126,6 @@ public class ImportAutoConfigurationImportSelectorTests { public void exclusionsAliasesAreApplied() throws Exception { AnnotationMetadata annotationMetadata = getAnnotationMetadata( ImportWithSelfAnnotatingAnnotationExclude.class); - String[] imports = this.importSelector.selectImports(annotationMetadata); assertThat(imports).isEmpty(); } @@ -182,6 +182,19 @@ public class ImportAutoConfigurationImportSelectorTests { assertThat(set1).isNotEqualTo(set2); } + @Test + public void determineImportsShouldNotSetPackageImport() throws Exception { + Class packageImportClass = ClassUtils.resolveClassName( + "org.springframework.boot.autoconfigure.AutoConfigurationPackages.PackageImport", + null); + Set selectedImports = this.importSelector + .determineImports(getAnnotationMetadata( + ImportMetaAutoConfigurationExcludeWithUnrelatedOne.class)); + for (Object selectedImport : selectedImports) { + assertThat(selectedImport).isNotInstanceOf(packageImportClass); + } + } + private AnnotationMetadata getAnnotationMetadata(Class source) throws IOException { return new SimpleMetadataReaderFactory().getMetadataReader(source.getName()) .getAnnotationMetadata(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java index 29651d6824..4db31347b9 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java @@ -67,116 +67,131 @@ public class ActiveMQAutoConfigurationTests { @Test public void defaultsConnectionFactoryAreApplied() { this.context.withUserConfiguration(EmptyConfiguration.class) - .withPropertyValues("spring.activemq.pool.enabled=false").run((loaded) -> { - assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class)).hasSize(1); - ActiveMQConnectionFactory connectionFactory = loaded.getBean( - ActiveMQConnectionFactory.class); - ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory( - "vm://localhost?broker.persistent=false"); - assertThat(connectionFactory.getUserName()).isEqualTo( - defaultFactory.getUserName()); - assertThat(connectionFactory.getPassword()).isEqualTo( - defaultFactory.getPassword()); - assertThat(connectionFactory.getCloseTimeout()).isEqualTo( - defaultFactory.getCloseTimeout()); - assertThat(connectionFactory.isNonBlockingRedelivery()).isEqualTo( - defaultFactory.isNonBlockingRedelivery()); - assertThat(connectionFactory.getSendTimeout()).isEqualTo( - defaultFactory.getSendTimeout()); - assertThat(connectionFactory.isTrustAllPackages()).isEqualTo( - defaultFactory.isTrustAllPackages()); - assertThat(connectionFactory.getTrustedPackages()).containsExactly( - defaultFactory.getTrustedPackages().toArray(new String[] {})); - }); + .withPropertyValues("spring.activemq.pool.enabled=false") + .run((loaded) -> { + assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class)) + .hasSize(1); + ActiveMQConnectionFactory connectionFactory = loaded + .getBean(ActiveMQConnectionFactory.class); + ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory( + "vm://localhost?broker.persistent=false"); + assertThat(connectionFactory.getUserName()) + .isEqualTo(defaultFactory.getUserName()); + assertThat(connectionFactory.getPassword()) + .isEqualTo(defaultFactory.getPassword()); + assertThat(connectionFactory.getCloseTimeout()) + .isEqualTo(defaultFactory.getCloseTimeout()); + assertThat(connectionFactory.isNonBlockingRedelivery()) + .isEqualTo(defaultFactory.isNonBlockingRedelivery()); + assertThat(connectionFactory.getSendTimeout()) + .isEqualTo(defaultFactory.getSendTimeout()); + assertThat(connectionFactory.isTrustAllPackages()) + .isEqualTo(defaultFactory.isTrustAllPackages()); + assertThat(connectionFactory.getTrustedPackages()).containsExactly( + defaultFactory.getTrustedPackages().toArray(new String[] {})); + }); } @Test public void customConnectionFactoryAreApplied() { this.context.withUserConfiguration(EmptyConfiguration.class) .withPropertyValues("spring.activemq.pool.enabled=false", - "spring.activemq.brokerUrl=vm://localhost?useJmx=false&broker.persistent=false", - "spring.activemq.user=foo", - "spring.activemq.password=bar", - "spring.activemq.closeTimeout=500", - "spring.activemq.nonBlockingRedelivery=true", - "spring.activemq.sendTimeout=1000", - "spring.activemq.packages.trust-all=false", - "spring.activemq.packages.trusted=com.example.acme").run((loaded) -> { - assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class)).hasSize(1); - ActiveMQConnectionFactory connectionFactory = loaded.getBean( - ActiveMQConnectionFactory.class); - assertThat(connectionFactory.getUserName()).isEqualTo("foo"); - assertThat(connectionFactory.getPassword()).isEqualTo("bar"); - assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500); - assertThat(connectionFactory.isNonBlockingRedelivery()).isEqualTo(true); - assertThat(connectionFactory.getSendTimeout()).isEqualTo(1000); - assertThat(connectionFactory.isTrustAllPackages()).isFalse(); - assertThat(connectionFactory.getTrustedPackages()).containsExactly( - "com.example.acme"); - }); + "spring.activemq.brokerUrl=vm://localhost?useJmx=false&broker.persistent=false", + "spring.activemq.user=foo", "spring.activemq.password=bar", + "spring.activemq.closeTimeout=500", + "spring.activemq.nonBlockingRedelivery=true", + "spring.activemq.sendTimeout=1000", + "spring.activemq.packages.trust-all=false", + "spring.activemq.packages.trusted=com.example.acme") + .run((loaded) -> { + assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class)) + .hasSize(1); + ActiveMQConnectionFactory connectionFactory = loaded + .getBean(ActiveMQConnectionFactory.class); + assertThat(connectionFactory.getUserName()).isEqualTo("foo"); + assertThat(connectionFactory.getPassword()).isEqualTo("bar"); + assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500); + assertThat(connectionFactory.isNonBlockingRedelivery()) + .isEqualTo(true); + assertThat(connectionFactory.getSendTimeout()).isEqualTo(1000); + assertThat(connectionFactory.isTrustAllPackages()).isFalse(); + assertThat(connectionFactory.getTrustedPackages()) + .containsExactly("com.example.acme"); + }); } @Test public void defaultsPooledConnectionFactoryAreApplied() { this.context.withUserConfiguration(EmptyConfiguration.class) .withPropertyValues("spring.activemq.pool.enabled=true").run((loaded) -> { - assertThat(loaded.getBeansOfType(PooledConnectionFactory.class)).hasSize(1); - PooledConnectionFactory connectionFactory = loaded.getBean( - PooledConnectionFactory.class); - PooledConnectionFactory defaultFactory = new PooledConnectionFactory(); - assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isEqualTo( - defaultFactory.isBlockIfSessionPoolIsFull()); - assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo( - defaultFactory.getBlockIfSessionPoolIsFullTimeout()); - assertThat(connectionFactory.isCreateConnectionOnStartup()).isEqualTo( - defaultFactory.isCreateConnectionOnStartup()); - assertThat(connectionFactory.getExpiryTimeout()).isEqualTo( - defaultFactory.getExpiryTimeout()); - assertThat(connectionFactory.getIdleTimeout()).isEqualTo( - defaultFactory.getIdleTimeout()); - assertThat(connectionFactory.getMaxConnections()).isEqualTo( - defaultFactory.getMaxConnections()); - assertThat(connectionFactory.getMaximumActiveSessionPerConnection()).isEqualTo( - defaultFactory.getMaximumActiveSessionPerConnection()); - assertThat(connectionFactory.isReconnectOnException()).isEqualTo( - defaultFactory.isReconnectOnException()); - assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()).isEqualTo( - defaultFactory.getTimeBetweenExpirationCheckMillis()); - assertThat(connectionFactory.isUseAnonymousProducers()).isEqualTo( - defaultFactory.isUseAnonymousProducers()); - }); + assertThat(loaded.getBeansOfType(PooledConnectionFactory.class)) + .hasSize(1); + PooledConnectionFactory connectionFactory = loaded + .getBean(PooledConnectionFactory.class); + PooledConnectionFactory defaultFactory = new PooledConnectionFactory(); + assertThat(connectionFactory.isBlockIfSessionPoolIsFull()) + .isEqualTo(defaultFactory.isBlockIfSessionPoolIsFull()); + assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()) + .isEqualTo( + defaultFactory.getBlockIfSessionPoolIsFullTimeout()); + assertThat(connectionFactory.isCreateConnectionOnStartup()) + .isEqualTo(defaultFactory.isCreateConnectionOnStartup()); + assertThat(connectionFactory.getExpiryTimeout()) + .isEqualTo(defaultFactory.getExpiryTimeout()); + assertThat(connectionFactory.getIdleTimeout()) + .isEqualTo(defaultFactory.getIdleTimeout()); + assertThat(connectionFactory.getMaxConnections()) + .isEqualTo(defaultFactory.getMaxConnections()); + assertThat(connectionFactory.getMaximumActiveSessionPerConnection()) + .isEqualTo(defaultFactory + .getMaximumActiveSessionPerConnection()); + assertThat(connectionFactory.isReconnectOnException()) + .isEqualTo(defaultFactory.isReconnectOnException()); + assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()) + .isEqualTo( + defaultFactory.getTimeBetweenExpirationCheckMillis()); + assertThat(connectionFactory.isUseAnonymousProducers()) + .isEqualTo(defaultFactory.isUseAnonymousProducers()); + }); } @Test public void customPooledConnectionFactoryAreApplied() { this.context.withUserConfiguration(EmptyConfiguration.class) .withPropertyValues("spring.activemq.pool.enabled=true", - "spring.activemq.pool.blockIfFull=false", - "spring.activemq.pool.blockIfFullTimeout=64", - "spring.activemq.pool.createConnectionOnStartup=false", - "spring.activemq.pool.expiryTimeout=4096", - "spring.activemq.pool.idleTimeout=512", - "spring.activemq.pool.maxConnections=256", - "spring.activemq.pool.maximumActiveSessionPerConnection=1024", - "spring.activemq.pool.reconnectOnException=false", - "spring.activemq.pool.timeBetweenExpirationCheck=2048", - "spring.activemq.pool.useAnonymousProducers=false").run((loaded) -> { - assertThat(loaded.getBeansOfType(PooledConnectionFactory.class)).hasSize(1); - PooledConnectionFactory connectionFactory = loaded.getBean( - PooledConnectionFactory.class); - assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isEqualTo(false); - assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo(64); - assertThat(connectionFactory.isCreateConnectionOnStartup()).isEqualTo(false); - assertThat(connectionFactory.getExpiryTimeout()).isEqualTo(4096); - assertThat(connectionFactory.getIdleTimeout()).isEqualTo(512); - assertThat(connectionFactory.getMaxConnections()).isEqualTo(256); - assertThat(connectionFactory.getMaximumActiveSessionPerConnection()) - .isEqualTo(1024); - assertThat(connectionFactory.isReconnectOnException()).isEqualTo(false); - assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()) - .isEqualTo(2048); - assertThat(connectionFactory.isUseAnonymousProducers()).isEqualTo(false); - }); + "spring.activemq.pool.blockIfFull=false", + "spring.activemq.pool.blockIfFullTimeout=64", + "spring.activemq.pool.createConnectionOnStartup=false", + "spring.activemq.pool.expiryTimeout=4096", + "spring.activemq.pool.idleTimeout=512", + "spring.activemq.pool.maxConnections=256", + "spring.activemq.pool.maximumActiveSessionPerConnection=1024", + "spring.activemq.pool.reconnectOnException=false", + "spring.activemq.pool.timeBetweenExpirationCheck=2048", + "spring.activemq.pool.useAnonymousProducers=false") + .run((loaded) -> { + assertThat(loaded.getBeansOfType(PooledConnectionFactory.class)) + .hasSize(1); + PooledConnectionFactory connectionFactory = loaded + .getBean(PooledConnectionFactory.class); + assertThat(connectionFactory.isBlockIfSessionPoolIsFull()) + .isEqualTo(false); + assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()) + .isEqualTo(64); + assertThat(connectionFactory.isCreateConnectionOnStartup()) + .isEqualTo(false); + assertThat(connectionFactory.getExpiryTimeout()).isEqualTo(4096); + assertThat(connectionFactory.getIdleTimeout()).isEqualTo(512); + assertThat(connectionFactory.getMaxConnections()).isEqualTo(256); + assertThat(connectionFactory.getMaximumActiveSessionPerConnection()) + .isEqualTo(1024); + assertThat(connectionFactory.isReconnectOnException()) + .isEqualTo(false); + assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()) + .isEqualTo(2048); + assertThat(connectionFactory.isUseAnonymousProducers()) + .isEqualTo(false); + }); } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java index 90280f5f70..fb3bb861cc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java @@ -40,37 +40,38 @@ public class ActiveMQPropertiesTests { @Test public void getBrokerUrlIsInMemoryByDefault() { - assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo( - DEFAULT_EMBEDDED_BROKER_URL); + assertThat(createFactory(this.properties).determineBrokerUrl()) + .isEqualTo(DEFAULT_EMBEDDED_BROKER_URL); } @Test public void getBrokerUrlUseExplicitBrokerUrl() { this.properties.setBrokerUrl("vm://foo-bar"); - assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo( - "vm://foo-bar"); + assertThat(createFactory(this.properties).determineBrokerUrl()) + .isEqualTo("vm://foo-bar"); } @Test public void getBrokerUrlWithInMemorySetToFalse() { this.properties.setInMemory(false); - assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo( - DEFAULT_NETWORK_BROKER_URL); + assertThat(createFactory(this.properties).determineBrokerUrl()) + .isEqualTo(DEFAULT_NETWORK_BROKER_URL); } @Test public void getExplicitBrokerUrlAlwaysWins() { this.properties.setBrokerUrl("vm://foo-bar"); this.properties.setInMemory(false); - assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo( - "vm://foo-bar"); + assertThat(createFactory(this.properties).determineBrokerUrl()) + .isEqualTo("vm://foo-bar"); } @Test public void setTrustAllPackages() { this.properties.getPackages().setTrustAll(true); - assertThat(createFactory(this.properties).createConnectionFactory( - ActiveMQConnectionFactory.class).isTrustAllPackages()).isEqualTo(true); + assertThat(createFactory(this.properties) + .createConnectionFactory(ActiveMQConnectionFactory.class) + .isTrustAllPackages()).isEqualTo(true); } @Test @@ -84,7 +85,8 @@ public class ActiveMQPropertiesTests { assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package"); } - private ActiveMQConnectionFactoryFactory createFactory(ActiveMQProperties properties) { + private ActiveMQConnectionFactoryFactory createFactory( + ActiveMQProperties properties) { return new ActiveMQConnectionFactoryFactory(properties, Collections.emptyList()); } diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java index 45d5dbbfdc..7399043c90 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java @@ -24,6 +24,7 @@ import org.junit.runner.notification.RunNotifier; import org.junit.runners.model.InitializationError; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @@ -94,8 +95,8 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests { } - @ContextConfiguration(classes = EmptyConfig.class) @DataJpaTest + @ContextConfiguration(classes = EmptyConfig.class) @Unrelated2 public static class DataJpaTest2 { @@ -109,8 +110,8 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests { } - @ContextConfiguration(classes = EmptyConfig.class) @DataJpaTest + @ContextConfiguration(classes = EmptyConfig.class) @Unrelated1 public static class DataJpaTest3 { @@ -124,8 +125,8 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests { } - @ContextConfiguration(classes = EmptyConfig.class) @DataJpaTest(showSql = false) + @ContextConfiguration(classes = EmptyConfig.class) @Unrelated1 public static class DataJpaTest4 { @@ -151,6 +152,7 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests { @Configuration @EntityScan(basePackageClasses = ExampleEntity.class) + @AutoConfigurationPackage static class EmptyConfig { } diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java index 4d4154c323..466d8f0397 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java @@ -71,8 +71,6 @@ public class Handler extends URLStreamHandler { rootFileCache = new SoftReference<>(null); } - private final Logger logger = Logger.getLogger(getClass().getName()); - private final JarFile jarFile; private URLStreamHandler fallbackHandler; @@ -105,10 +103,10 @@ public class Handler extends URLStreamHandler { } catch (Exception ex) { if (reason instanceof IOException) { - this.logger.log(Level.FINEST, "Unable to open fallback handler", ex); + log(false, "Unable to open fallback handler", ex); throw (IOException) reason; } - this.logger.log(Level.WARNING, "Unable to open fallback handler", ex); + log(true, "Unable to open fallback handler", ex); if (reason instanceof RuntimeException) { throw (RuntimeException) reason; } @@ -116,6 +114,18 @@ public class Handler extends URLStreamHandler { } } + private void log(boolean warning, String message, Exception cause) { + try { + Logger.getLogger(getClass().getName()) + .log((warning ? Level.WARNING : Level.FINEST), message, cause); + } + catch (Exception ex) { + if (warning) { + System.err.println("WARNING: " + message); + } + } + } + private URLStreamHandler getFallbackHandler() { if (this.fallbackHandler != null) { return this.fallbackHandler;