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
0d0de05a
Commit
0d0de05a
authored
Dec 18, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for Groovy bean builder sources
parent
d635d8af
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
2 deletions
+46
-2
pom.xml
spring-boot/pom.xml
+5
-0
BeanDefinitionLoader.java
...n/java/org/springframework/boot/BeanDefinitionLoader.java
+16
-2
BeanDefinitionLoaderTests.java
...a/org/springframework/boot/BeanDefinitionLoaderTests.java
+20
-0
sample-beans.groovy
...st/resources/org/springframework/boot/sample-beans.groovy
+5
-0
No files found.
spring-boot/pom.xml
View file @
0d0de05a
...
...
@@ -49,6 +49,11 @@
<artifactId>
tomcat-embed-core
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.codehaus.groovy
</groupId>
<artifactId>
groovy
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.eclipse.jetty
</groupId>
<artifactId>
jetty-webapp
</artifactId>
...
...
spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java
View file @
0d0de05a
...
...
@@ -20,6 +20,8 @@ import java.io.IOException;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.beans.factory.BeanDefinitionStoreException
;
import
org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
;
...
...
@@ -57,6 +59,8 @@ class BeanDefinitionLoader {
private
XmlBeanDefinitionReader
xmlReader
;
private
GroovyBeanDefinitionReader
groovyReader
;
private
ClassPathBeanDefinitionScanner
scanner
;
private
ResourceLoader
resourceLoader
;
...
...
@@ -73,6 +77,9 @@ class BeanDefinitionLoader {
this
.
sources
=
sources
;
this
.
annotatedReader
=
new
AnnotatedBeanDefinitionReader
(
registry
);
this
.
xmlReader
=
new
XmlBeanDefinitionReader
(
registry
);
if
(
ClassUtils
.
isPresent
(
"groovy.lang.MetaClass"
,
null
))
{
this
.
groovyReader
=
new
GroovyBeanDefinitionReader
(
this
.
xmlReader
);
}
this
.
scanner
=
new
ClassPathBeanDefinitionScanner
(
registry
);
this
.
scanner
.
addExcludeFilter
(
new
ClassExcludeFilter
(
sources
));
}
...
...
@@ -145,6 +152,13 @@ class BeanDefinitionLoader {
}
private
int
load
(
Resource
source
)
{
if
(
source
.
getFilename
().
endsWith
(
".groovy"
))
{
if
(
this
.
groovyReader
==
null
)
{
throw
new
BeanDefinitionStoreException
(
"Cannot load Groovy beans without Groovy on classpath"
);
}
return
this
.
groovyReader
.
loadBeanDefinitions
(
source
);
}
return
this
.
xmlReader
.
loadBeanDefinitions
(
source
);
}
...
...
@@ -169,7 +183,7 @@ class BeanDefinitionLoader {
}
// Attempt as resources
Resource
[]
resources
=
loa
dResources
(
resolvedSource
);
Resource
[]
resources
=
fin
dResources
(
resolvedSource
);
int
loadCount
=
0
;
boolean
atLeastOneResourceExists
=
false
;
for
(
Resource
resource
:
resources
)
{
...
...
@@ -191,7 +205,7 @@ class BeanDefinitionLoader {
throw
new
IllegalArgumentException
(
"Invalid source '"
+
resolvedSource
+
"'"
);
}
private
Resource
[]
loa
dResources
(
String
source
)
{
private
Resource
[]
fin
dResources
(
String
source
)
{
ResourceLoader
loader
=
this
.
resourceLoader
!=
null
?
this
.
resourceLoader
:
DEFAULT_RESOURCE_LOADER
;
try
{
...
...
spring-boot/src/test/java/org/springframework/boot/BeanDefinitionLoaderTests.java
View file @
0d0de05a
...
...
@@ -61,6 +61,17 @@ public class BeanDefinitionLoaderTests {
}
@Test
public
void
loadGroovyResource
()
throws
Exception
{
ClassPathResource
resource
=
new
ClassPathResource
(
"sample-beans.groovy"
,
getClass
());
BeanDefinitionLoader
loader
=
new
BeanDefinitionLoader
(
this
.
registry
,
resource
);
int
loaded
=
loader
.
load
();
assertThat
(
loaded
,
equalTo
(
1
));
assertTrue
(
this
.
registry
.
containsBean
(
"myGroovyComponent"
));
}
@Test
public
void
loadPackage
()
throws
Exception
{
BeanDefinitionLoader
loader
=
new
BeanDefinitionLoader
(
this
.
registry
,
...
...
@@ -88,6 +99,15 @@ public class BeanDefinitionLoaderTests {
assertTrue
(
this
.
registry
.
containsBean
(
"myXmlComponent"
));
}
@Test
public
void
loadGroovyName
()
throws
Exception
{
BeanDefinitionLoader
loader
=
new
BeanDefinitionLoader
(
this
.
registry
,
"classpath:org/springframework/boot/sample-beans.groovy"
);
int
loaded
=
loader
.
load
();
assertThat
(
loaded
,
equalTo
(
1
));
assertTrue
(
this
.
registry
.
containsBean
(
"myGroovyComponent"
));
}
@Test
public
void
loadPackageName
()
throws
Exception
{
BeanDefinitionLoader
loader
=
new
BeanDefinitionLoader
(
this
.
registry
,
...
...
spring-boot/src/test/resources/org/springframework/boot/sample-beans.groovy
0 → 100644
View file @
0d0de05a
import
org.springframework.boot.sampleconfig.MyComponent
;
beans
{
myGroovyComponent
(
MyComponent
)
{}
}
\ No newline at end of file
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