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
ed64640e
Commit
ed64640e
authored
May 01, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch from @Bean to protected method
parent
524e95ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
18 deletions
+23
-18
WebMvcAutoConfiguration.java
...ework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
+8
-7
WebMvcAutoConfigurationTests.java
.../boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
+15
-11
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java
View file @
ed64640e
...
...
@@ -200,13 +200,14 @@ public class WebMvcAutoConfiguration {
return
new
FixedLocaleResolver
(
StringUtils
.
parseLocaleString
(
this
.
locale
));
}
@Bean
@ConditionalOnMissingBean
(
MessageCodesResolver
.
class
)
@ConditionalOnExpression
(
"'${spring.mvc.message-codes-resolver.format:}' != ''"
)
public
MessageCodesResolver
messageCodesResolver
()
{
DefaultMessageCodesResolver
resolver
=
new
DefaultMessageCodesResolver
();
resolver
.
setMessageCodeFormatter
(
this
.
messageCodesResolverFormat
);
return
resolver
;
@Override
public
MessageCodesResolver
getMessageCodesResolver
()
{
if
(
this
.
messageCodesResolverFormat
!=
null
)
{
DefaultMessageCodesResolver
resolver
=
new
DefaultMessageCodesResolver
();
resolver
.
setMessageCodeFormatter
(
this
.
messageCodesResolverFormat
);
return
resolver
;
}
return
null
;
}
@Override
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java
View file @
ed64640e
...
...
@@ -16,12 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.lang.reflect.Field
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
...
...
@@ -37,6 +31,7 @@ import org.junit.Test;
import
org.junit.rules.ExpectedException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter
;
import
org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
;
...
...
@@ -49,7 +44,6 @@ import org.springframework.core.io.Resource;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.validation.MessageCodesResolver
;
import
org.springframework.web.servlet.HandlerAdapter
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.servlet.LocaleResolver
;
...
...
@@ -62,6 +56,14 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
import
org.springframework.web.servlet.resource.ResourceHttpRequestHandler
;
import
org.springframework.web.servlet.view.AbstractView
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Tests for {@link WebMvcAutoConfiguration}.
*
...
...
@@ -181,15 +183,16 @@ public class WebMvcAutoConfigurationTests {
assertThat
(
locale
.
toString
(),
equalTo
(
"en_UK"
));
}
@Test
(
expected
=
NoSuchBeanDefinitionException
.
class
)
public
void
noMessageCodeResolver
()
throws
Exception
{
@Test
public
void
noMessageCode
s
Resolver
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
AllResources
.
class
,
Config
.
class
,
WebMvcAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
getBean
(
MessageCodesResolver
.
class
);
assertNull
(
this
.
context
.
getBean
(
WebMvcAutoConfigurationAdapter
.
class
)
.
getMessageCodesResolver
());
}
@Test
...
...
@@ -202,7 +205,8 @@ public class WebMvcAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
this
.
context
.
getBean
(
MessageCodesResolver
.
class
);
assertNotNull
(
this
.
context
.
getBean
(
WebMvcAutoConfigurationAdapter
.
class
)
.
getMessageCodesResolver
());
}
@SuppressWarnings
(
"unchecked"
)
...
...
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