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
2d76de29
Commit
2d76de29
authored
Oct 01, 2020
by
Shraddha Yeole
Committed by
Madhura Bhave
Oct 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not fail if h2Console bean cannot connect to db
See gh-23566
parent
3118ca93
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
H2ConsoleAutoConfiguration.java
...ork/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java
+1
-1
H2ConsoleAutoConfigurationTests.java
...oot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java
+26
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java
View file @
2d76de29
...
...
@@ -74,7 +74,7 @@ public class H2ConsoleAutoConfiguration {
logger
.
info
(
"H2 console available at '"
+
path
+
"'. Database available at '"
+
connection
.
getMetaData
().
getURL
()
+
"'"
);
}
catch
(
SQL
Exception
ex
)
{
catch
(
Exception
ex
)
{
// Continue
}
});
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java
View file @
2d76de29
...
...
@@ -17,11 +17,13 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
h2
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
javax.sql.DataSource
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.BDDMockito
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanCreationException
;
...
...
@@ -31,8 +33,11 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import
org.springframework.boot.test.system.CapturedOutput
;
import
org.springframework.boot.test.system.OutputCaptureExtension
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link H2ConsoleAutoConfiguration}
...
...
@@ -117,4 +122,25 @@ class H2ConsoleAutoConfigurationTests {
});
}
@Test
void
testDataSource
()
{
this
.
contextRunner
.
withUserConfiguration
(
DataSourceAvailable
.
class
)
.
withPropertyValues
(
"spring.h2.console.enabled=true"
).
run
((
context
)
->
{
assertThat
(
context
.
isRunning
()).
isTrue
();
});
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
DataSourceAvailable
{
@Bean
public
DataSource
dataSource
()
throws
SQLException
{
DataSource
dataSource
=
mock
(
DataSource
.
class
);
BDDMockito
.
when
(
dataSource
.
getConnection
()).
thenThrow
(
IllegalStateException
.
class
);
return
dataSource
;
}
}
}
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