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
d3f180b6
Commit
d3f180b6
authored
Apr 12, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
7f270356
715cf7da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
+31
-7
PersistenceExceptionTranslationAutoConfiguration.java
...dao/PersistenceExceptionTranslationAutoConfiguration.java
+14
-3
PersistenceExceptionTranslationAutoConfigurationTests.java
...ersistenceExceptionTranslationAutoConfigurationTests.java
+17
-4
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfiguration.java
View file @
d3f180b6
/*
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -20,7 +20,9 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
...
@@ -20,7 +20,9 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
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
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
import
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
;
import
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
;
/**
/**
...
@@ -28,6 +30,7 @@ import org.springframework.dao.annotation.PersistenceExceptionTranslationPostPro
...
@@ -28,6 +30,7 @@ import org.springframework.dao.annotation.PersistenceExceptionTranslationPostPro
* translation.
* translation.
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Stephane Nicoll
* @since 1.2.0
* @since 1.2.0
*/
*/
@ConditionalOnClass
(
PersistenceExceptionTranslationPostProcessor
.
class
)
@ConditionalOnClass
(
PersistenceExceptionTranslationPostProcessor
.
class
)
...
@@ -36,10 +39,18 @@ public class PersistenceExceptionTranslationAutoConfiguration {
...
@@ -36,10 +39,18 @@ public class PersistenceExceptionTranslationAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
(
PersistenceExceptionTranslationPostProcessor
.
class
)
@ConditionalOnMissingBean
(
PersistenceExceptionTranslationPostProcessor
.
class
)
@ConditionalOnProperty
(
prefix
=
"spring.dao.exceptiontranslation"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
@ConditionalOnProperty
(
prefix
=
"spring.dao.exceptiontranslation"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
public
static
PersistenceExceptionTranslationPostProcessor
persistenceExceptionTranslationPostProcessor
()
{
public
static
PersistenceExceptionTranslationPostProcessor
persistenceExceptionTranslationPostProcessor
(
Environment
environment
)
{
PersistenceExceptionTranslationPostProcessor
postProcessor
=
new
PersistenceExceptionTranslationPostProcessor
();
PersistenceExceptionTranslationPostProcessor
postProcessor
=
new
PersistenceExceptionTranslationPostProcessor
();
postProcessor
.
setProxyTargetClass
(
true
);
postProcessor
.
setProxyTargetClass
(
determineProxyTargetClass
(
environment
)
);
return
postProcessor
;
return
postProcessor
;
}
}
private
static
boolean
determineProxyTargetClass
(
Environment
environment
)
{
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
environment
,
"spring.aop."
);
Boolean
value
=
resolver
.
getProperty
(
"proxyTargetClass"
,
Boolean
.
class
);
return
(
value
!=
null
?
value
:
true
);
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfigurationTests.java
View file @
d3f180b6
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -37,10 +37,10 @@ import org.springframework.stereotype.Repository;
...
@@ -37,10 +37,10 @@ import org.springframework.stereotype.Repository;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
/**
*
* Tests for {@link PersistenceExceptionTranslationAutoConfiguration}
* Tests for {@link PersistenceExceptionTranslationAutoConfiguration}
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
*/
public
class
PersistenceExceptionTranslationAutoConfigurationTests
{
public
class
PersistenceExceptionTranslationAutoConfigurationTests
{
...
@@ -54,7 +54,7 @@ public class PersistenceExceptionTranslationAutoConfigurationTests {
...
@@ -54,7 +54,7 @@ public class PersistenceExceptionTranslationAutoConfigurationTests {
}
}
@Test
@Test
public
void
exceptionTranslationPostProcessor
BeanIsCreated
()
{
public
void
exceptionTranslationPostProcessor
UsesCglibByDefault
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
(
this
.
context
=
new
AnnotationConfigApplicationContext
(
PersistenceExceptionTranslationAutoConfiguration
.
class
);
PersistenceExceptionTranslationAutoConfiguration
.
class
);
Map
<
String
,
PersistenceExceptionTranslationPostProcessor
>
beans
=
this
.
context
Map
<
String
,
PersistenceExceptionTranslationPostProcessor
>
beans
=
this
.
context
...
@@ -64,7 +64,20 @@ public class PersistenceExceptionTranslationAutoConfigurationTests {
...
@@ -64,7 +64,20 @@ public class PersistenceExceptionTranslationAutoConfigurationTests {
}
}
@Test
@Test
public
void
exceptionTranslationPostProcessorBeanIsDisabled
()
{
public
void
exceptionTranslationPostProcessorCanBeConfiguredToUseJdkProxy
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.aop.proxyTargetClass=false"
);
this
.
context
.
register
(
PersistenceExceptionTranslationAutoConfiguration
.
class
);
this
.
context
.
refresh
();
Map
<
String
,
PersistenceExceptionTranslationPostProcessor
>
beans
=
this
.
context
.
getBeansOfType
(
PersistenceExceptionTranslationPostProcessor
.
class
);
assertThat
(
beans
).
hasSize
(
1
);
assertThat
(
beans
.
values
().
iterator
().
next
().
isProxyTargetClass
()).
isFalse
();
}
@Test
public
void
exceptionTranslationPostProcessorCanBeDisabled
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.dao.exceptiontranslation.enabled=false"
);
"spring.dao.exceptiontranslation.enabled=false"
);
...
...
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