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
a4143b88
Commit
a4143b88
authored
Aug 22, 2013
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish pattern resolving in BeanDefinitionLoader
parent
507c4ec7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
37 deletions
+33
-37
BeanDefinitionLoader.java
...n/java/org/springframework/boot/BeanDefinitionLoader.java
+33
-37
No files found.
spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java
View file @
a4143b88
...
...
@@ -20,7 +20,6 @@ import java.io.IOException;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.beans.factory.BeanDefinitionStoreException
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
;
...
...
@@ -154,56 +153,53 @@ class BeanDefinitionLoader {
}
private
int
load
(
CharSequence
source
)
{
String
sourceString
=
this
.
xmlReader
.
getEnvironment
().
resolvePlaceholders
(
String
resolvedSource
=
this
.
xmlReader
.
getEnvironment
().
resolvePlaceholders
(
source
.
toString
());
// Attempt as a Class
try
{
// Use class utils so that period separated nested class names work
return
load
(
ClassUtils
.
forName
(
sourceString
,
null
));
return
load
(
ClassUtils
.
forName
(
resolvedSource
,
null
));
}
catch
(
ClassNotFoundException
ex
)
{
// swallow exception and continue
}
ResourceLoader
loader
=
this
.
resourceLoader
!=
null
?
this
.
resourceLoader
:
DEFAULT_RESOURCE_LOADER
;
// Attempt as resources
Resource
[]
resources
=
loadResources
(
resolvedSource
);
int
loadCount
=
0
;
if
(
loader
instanceof
ResourcePatternResolver
)
{
// Resource pattern matching available.
try
{
Resource
[]
resources
=
((
ResourcePatternResolver
)
loader
)
.
getResources
(
sourceString
);
for
(
Resource
resource
:
resources
)
{
if
(
resource
.
exists
())
{
loadCount
+=
load
(
resource
);
}
}
}
catch
(
IOException
ex
)
{
throw
new
BeanDefinitionStoreException
(
"Could not resolve bean definition resource pattern ["
+
sourceString
+
"]"
,
ex
);
}
}
if
(!(
loader
instanceof
ResourcePatternResolver
))
{
// Can only load single resources by absolute URL.
Resource
loadedResource
=
loader
.
getResource
(
sourceString
);
if
(
loadedResource
!=
null
&&
loadedResource
.
exists
())
{
return
load
(
loadedResource
);
boolean
atLeastOneResourceExists
=
false
;
for
(
Resource
resource
:
resources
)
{
if
(
resource
!=
null
&&
resource
.
exists
())
{
atLeastOneResourceExists
=
true
;
loadCount
+=
load
(
resource
);
}
}
if
(
loadCount
>
0
)
{
if
(
atLeastOneResourceExists
)
{
return
loadCount
;
}
else
{
// Attempt to treat the source as a package name, common to all
// PatternResolver types
Package
packageResource
=
findPackage
(
source
);
if
(
packageResource
!=
null
)
{
return
load
(
packageResource
);
// Attempt as package
Package
packageResource
=
findPackage
(
resolvedSource
);
if
(
packageResource
!=
null
)
{
return
load
(
packageResource
);
}
throw
new
IllegalArgumentException
(
"Invalid source '"
+
resolvedSource
+
"'"
);
}
private
Resource
[]
loadResources
(
String
source
)
{
ResourceLoader
loader
=
this
.
resourceLoader
!=
null
?
this
.
resourceLoader
:
DEFAULT_RESOURCE_LOADER
;
try
{
if
(
loader
instanceof
ResourcePatternResolver
)
{
return
((
ResourcePatternResolver
)
loader
).
getResources
(
source
);
}
return
new
Resource
[]
{
loader
.
getResource
(
source
)
};
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
"Error reading source '"
+
source
+
"'"
);
}
throw
new
IllegalArgumentException
(
"Invalid source '"
+
source
+
"'"
);
}
private
Package
findPackage
(
CharSequence
source
)
{
...
...
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