Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
982f41b7
Commit
982f41b7
authored
Dec 22, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish @IntegrationComponentScan auto-configuration
See gh-2037 See gh-7718
parent
a79f71cb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
191 additions
and
65 deletions
+191
-65
IntegrationAutoConfiguration.java
...toconfigure/integration/IntegrationAutoConfiguration.java
+13
-44
IntegrationAutoConfigurationScanRegistrar.java
...ntegration/IntegrationAutoConfigurationScanRegistrar.java
+87
-0
IntegrationAutoConfigurationTests.java
...figure/integration/IntegrationAutoConfigurationTests.java
+8
-6
SampleCommandLineRunner.java
...main/java/sample/integration/SampleCommandLineRunner.java
+38
-0
SampleMessageGateway.java
...rc/main/java/sample/integration/SampleMessageGateway.java
+26
-0
SampleIntegrationApplicationTests.java
...tegration/consumer/SampleIntegrationApplicationTests.java
+19
-15
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java
View file @
982f41b7
...
@@ -16,15 +16,11 @@
...
@@ -16,15 +16,11 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
integration
;
package
org
.
springframework
.
boot
.
autoconfigure
.
integration
;
import
java.util.Map
;
import
javax.management.MBeanServer
;
import
javax.management.MBeanServer
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
...
@@ -37,12 +33,8 @@ import org.springframework.context.annotation.Bean;
...
@@ -37,12 +33,8 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.type.AnnotationMetadata
;
import
org.springframework.core.type.StandardAnnotationMetadata
;
import
org.springframework.integration.annotation.IntegrationComponentScan
;
import
org.springframework.integration.config.EnableIntegration
;
import
org.springframework.integration.config.EnableIntegration
;
import
org.springframework.integration.config.EnableIntegrationManagement
;
import
org.springframework.integration.config.EnableIntegrationManagement
;
import
org.springframework.integration.config.IntegrationComponentScanRegistrar
;
import
org.springframework.integration.gateway.GatewayProxyFactoryBean
;
import
org.springframework.integration.gateway.GatewayProxyFactoryBean
;
import
org.springframework.integration.jmx.config.EnableIntegrationMBeanExport
;
import
org.springframework.integration.jmx.config.EnableIntegrationMBeanExport
;
import
org.springframework.integration.monitor.IntegrationMBeanExporter
;
import
org.springframework.integration.monitor.IntegrationMBeanExporter
;
...
@@ -63,12 +55,18 @@ import org.springframework.util.StringUtils;
...
@@ -63,12 +55,18 @@ import org.springframework.util.StringUtils;
@AutoConfigureAfter
(
JmxAutoConfiguration
.
class
)
@AutoConfigureAfter
(
JmxAutoConfiguration
.
class
)
public
class
IntegrationAutoConfiguration
{
public
class
IntegrationAutoConfiguration
{
/**
* Basic Spring Integration configuration.
*/
@Configuration
@Configuration
@EnableIntegration
@EnableIntegration
protected
static
class
IntegrationConfiguration
{
protected
static
class
IntegrationConfiguration
{
}
}
/**
* Spring Integration JMX configuration.
*/
@Configuration
@Configuration
@ConditionalOnClass
(
EnableIntegrationMBeanExport
.
class
)
@ConditionalOnClass
(
EnableIntegrationMBeanExport
.
class
)
@ConditionalOnMissingBean
(
value
=
IntegrationMBeanExporter
.
class
,
search
=
SearchStrategy
.
CURRENT
)
@ConditionalOnMissingBean
(
value
=
IntegrationMBeanExporter
.
class
,
search
=
SearchStrategy
.
CURRENT
)
...
@@ -107,6 +105,9 @@ public class IntegrationAutoConfiguration {
...
@@ -107,6 +105,9 @@ public class IntegrationAutoConfiguration {
}
}
/**
* Integration management configuration.
*/
@Configuration
@Configuration
@ConditionalOnClass
({
EnableIntegrationManagement
.
class
,
@ConditionalOnClass
({
EnableIntegrationManagement
.
class
,
EnableIntegrationMBeanExport
.
class
})
EnableIntegrationMBeanExport
.
class
})
...
@@ -121,45 +122,13 @@ public class IntegrationAutoConfiguration {
...
@@ -121,45 +122,13 @@ public class IntegrationAutoConfiguration {
}
}
/**
* Integration component scan configuration.
*/
@ConditionalOnMissingBean
(
GatewayProxyFactoryBean
.
class
)
@ConditionalOnMissingBean
(
GatewayProxyFactoryBean
.
class
)
@Import
(
AutoIntegrationComponent
ScanRegistrar
.
class
)
@Import
(
IntegrationAutoConfiguration
ScanRegistrar
.
class
)
protected
static
class
IntegrationComponentScanAutoConfiguration
{
protected
static
class
IntegrationComponentScanAutoConfiguration
{
}
}
private
static
class
AutoIntegrationComponentScanRegistrar
extends
IntegrationComponentScanRegistrar
{
@Override
public
void
registerBeanDefinitions
(
AnnotationMetadata
importingClassMetadata
,
final
BeanDefinitionRegistry
registry
)
{
StandardAnnotationMetadata
metadata
=
new
StandardAnnotationMetadata
(
IntegrationComponentScanConfiguration
.
class
,
true
)
{
@Override
public
Map
<
String
,
Object
>
getAnnotationAttributes
(
String
annotationName
)
{
Map
<
String
,
Object
>
annotationAttributes
=
super
.
getAnnotationAttributes
(
annotationName
);
if
(
IntegrationComponentScan
.
class
.
getName
().
equals
(
annotationName
))
{
BeanFactory
beanFactory
=
(
BeanFactory
)
registry
;
if
(
AutoConfigurationPackages
.
has
(
beanFactory
))
{
annotationAttributes
.
put
(
"value"
,
AutoConfigurationPackages
.
get
(
beanFactory
));
}
}
return
annotationAttributes
;
}
};
super
.
registerBeanDefinitions
(
metadata
,
registry
);
}
@IntegrationComponentScan
private
class
IntegrationComponentScanConfiguration
{
}
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationScanRegistrar.java
0 → 100644
View file @
982f41b7
/*
* Copyright 2012-2016 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
.
integration
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.core.type.AnnotationMetadata
;
import
org.springframework.core.type.StandardAnnotationMetadata
;
import
org.springframework.integration.annotation.IntegrationComponentScan
;
import
org.springframework.integration.config.IntegrationComponentScanRegistrar
;
/**
* Variation of {@link IntegrationComponentScanRegistrar} the links
* {@link AutoConfigurationPackages}.
*
* @author Artem Bilan
* @author Phillip Webb
*/
class
IntegrationAutoConfigurationScanRegistrar
extends
IntegrationComponentScanRegistrar
implements
BeanFactoryAware
{
private
BeanFactory
beanFactory
;
@Override
public
void
setBeanFactory
(
BeanFactory
beanFactory
)
throws
BeansException
{
this
.
beanFactory
=
beanFactory
;
}
@Override
public
void
registerBeanDefinitions
(
AnnotationMetadata
importingClassMetadata
,
final
BeanDefinitionRegistry
registry
)
{
super
.
registerBeanDefinitions
(
new
IntegrationComponentScanConfigurationMetaData
(
this
.
beanFactory
),
registry
);
}
private
static
class
IntegrationComponentScanConfigurationMetaData
extends
StandardAnnotationMetadata
{
private
final
BeanFactory
beanFactory
;
IntegrationComponentScanConfigurationMetaData
(
BeanFactory
beanFactory
)
{
super
(
IntegrationComponentScanConfiguration
.
class
,
true
);
this
.
beanFactory
=
beanFactory
;
}
@Override
public
Map
<
String
,
Object
>
getAnnotationAttributes
(
String
annotationName
)
{
Map
<
String
,
Object
>
attributes
=
super
.
getAnnotationAttributes
(
annotationName
);
if
(
IntegrationComponentScan
.
class
.
getName
().
equals
(
annotationName
)
&&
AutoConfigurationPackages
.
has
(
this
.
beanFactory
))
{
List
<
String
>
packages
=
AutoConfigurationPackages
.
get
(
this
.
beanFactory
);
attributes
=
new
LinkedHashMap
<
String
,
Object
>(
attributes
);
attributes
.
put
(
"value"
,
packages
.
toArray
(
new
String
[
packages
.
size
()]));
}
return
attributes
;
}
}
@IntegrationComponentScan
private
static
class
IntegrationComponentScanConfiguration
{
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java
View file @
982f41b7
...
@@ -24,6 +24,7 @@ import javax.management.MBeanServer;
...
@@ -24,6 +24,7 @@ import javax.management.MBeanServer;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration.IntegrationComponentScanAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
...
@@ -65,7 +66,7 @@ public class IntegrationAutoConfigurationTests {
...
@@ -65,7 +66,7 @@ public class IntegrationAutoConfigurationTests {
public
void
integrationIsAvailable
()
{
public
void
integrationIsAvailable
()
{
load
();
load
();
assertThat
(
this
.
context
.
getBean
(
TestGateway
.
class
)).
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
TestGateway
.
class
)).
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
Integration
AutoConfiguration
.
Integration
ComponentScanAutoConfiguration
.
class
))
assertThat
(
this
.
context
.
getBean
(
IntegrationComponentScanAutoConfiguration
.
class
))
.
isNotNull
();
.
isNotNull
();
}
}
...
@@ -73,12 +74,12 @@ public class IntegrationAutoConfigurationTests {
...
@@ -73,12 +74,12 @@ public class IntegrationAutoConfigurationTests {
public
void
explicitIntegrationComponentScan
()
{
public
void
explicitIntegrationComponentScan
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
register
(
IntegrationComponentScanConfiguration
.
class
,
this
.
context
.
register
(
IntegrationComponentScanConfiguration
.
class
,
JmxAutoConfiguration
.
class
,
JmxAutoConfiguration
.
class
,
IntegrationAutoConfiguration
.
class
);
IntegrationAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
TestGateway
.
class
)).
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
TestGateway
.
class
)).
isNotNull
();
assertThat
(
this
.
context
.
getBeansOfType
(
IntegrationAutoConfiguration
.
IntegrationComponentScanAutoConfiguration
.
class
))
assertThat
(
this
.
context
.
isEmpty
();
.
getBeansOfType
(
IntegrationComponentScanAutoConfiguration
.
class
))
.
isEmpty
();
}
}
@Test
@Test
...
@@ -89,7 +90,8 @@ public class IntegrationAutoConfigurationTests {
...
@@ -89,7 +90,8 @@ public class IntegrationAutoConfigurationTests {
this
.
context
.
setParent
(
parent
);
this
.
context
.
setParent
(
parent
);
this
.
context
.
register
(
JmxAutoConfiguration
.
class
,
this
.
context
.
register
(
JmxAutoConfiguration
.
class
,
IntegrationAutoConfiguration
.
class
);
IntegrationAutoConfiguration
.
class
);
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
"SPRING_JMX_DEFAULT_DOMAIN=org.foo"
);
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
"SPRING_JMX_DEFAULT_DOMAIN=org.foo"
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
HeaderChannelRegistry
.
class
)).
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
HeaderChannelRegistry
.
class
)).
isNotNull
();
}
}
...
...
spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleCommandLineRunner.java
0 → 100644
View file @
982f41b7
/*
* Copyright 2012-2016 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
sample
.
integration
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Component
;
@Component
public
class
SampleCommandLineRunner
implements
CommandLineRunner
{
private
final
SampleMessageGateway
gateway
;
public
SampleCommandLineRunner
(
SampleMessageGateway
gateway
)
{
this
.
gateway
=
gateway
;
}
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
for
(
String
arg
:
args
)
{
this
.
gateway
.
echo
(
arg
);
}
}
}
spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleMessageGateway.java
0 → 100644
View file @
982f41b7
/*
* Copyright 2012-2016 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
sample
.
integration
;
import
org.springframework.integration.annotation.MessagingGateway
;
@MessagingGateway
(
defaultRequestChannel
=
"outputChannel"
)
public
interface
SampleMessageGateway
{
void
echo
(
String
message
);
}
spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java
View file @
982f41b7
...
@@ -23,9 +23,8 @@ import java.util.concurrent.Executors;
...
@@ -23,9 +23,8 @@ import java.util.concurrent.Executors;
import
java.util.concurrent.Future
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
org.junit.After
Class
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.Test
;
import
sample.integration.SampleIntegrationApplication
;
import
sample.integration.SampleIntegrationApplication
;
import
sample.integration.producer.ProducerApplication
;
import
sample.integration.producer.ProducerApplication
;
...
@@ -48,32 +47,37 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -48,32 +47,37 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
public
class
SampleIntegrationApplicationTests
{
public
class
SampleIntegrationApplicationTests
{
private
static
ConfigurableApplicationContext
context
;
private
ConfigurableApplicationContext
context
;
@BeforeClass
public
static
void
start
()
throws
Exception
{
context
=
SpringApplication
.
run
(
SampleIntegrationApplication
.
class
);
}
@AfterClass
public
static
void
stop
()
{
if
(
context
!=
null
)
{
context
.
close
();
}
}
@Before
@Before
public
void
deleteOutput
()
{
public
void
deleteOutput
()
{
FileSystemUtils
.
deleteRecursively
(
new
File
(
"target/input"
));
FileSystemUtils
.
deleteRecursively
(
new
File
(
"target/output"
));
FileSystemUtils
.
deleteRecursively
(
new
File
(
"target/output"
));
}
}
@After
public
void
stop
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
@Test
public
void
testVanillaExchange
()
throws
Exception
{
public
void
testVanillaExchange
()
throws
Exception
{
this
.
context
=
SpringApplication
.
run
(
SampleIntegrationApplication
.
class
);
SpringApplication
.
run
(
ProducerApplication
.
class
,
"World"
);
SpringApplication
.
run
(
ProducerApplication
.
class
,
"World"
);
String
output
=
getOutput
();
String
output
=
getOutput
();
assertThat
(
output
).
contains
(
"Hello World"
);
assertThat
(
output
).
contains
(
"Hello World"
);
}
}
@Test
public
void
testMessageGateway
()
throws
Exception
{
this
.
context
=
SpringApplication
.
run
(
SampleIntegrationApplication
.
class
,
"testviamg"
);
String
output
=
getOutput
();
assertThat
(
output
).
contains
(
"testviamg"
);
}
private
String
getOutput
()
throws
Exception
{
private
String
getOutput
()
throws
Exception
{
Future
<
String
>
future
=
Executors
.
newSingleThreadExecutor
()
Future
<
String
>
future
=
Executors
.
newSingleThreadExecutor
()
.
submit
(
new
Callable
<
String
>()
{
.
submit
(
new
Callable
<
String
>()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment