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
bca83bde
Commit
bca83bde
authored
Mar 18, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-5417
parent
ec8b94f1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
16 deletions
+55
-16
H2ConsoleAutoConfiguration.java
...ork/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java
+8
-2
H2ConsoleProperties.java
...gframework/boot/autoconfigure/h2/H2ConsoleProperties.java
+34
-9
H2ConsoleAutoConfigurationTests.java
...oot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java
+11
-5
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+2
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java
View file @
bca83bde
...
...
@@ -41,6 +41,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
* {@link EnableAutoConfiguration Auto-configuration} for H2's web console.
*
* @author Andy Wilkinson
* @author Marten Deinum
* @author Stephane Nicoll
* @since 1.3.0
*/
@Configuration
...
...
@@ -62,8 +64,12 @@ public class H2ConsoleAutoConfiguration {
String
path
=
this
.
properties
.
getPath
();
String
urlMapping
=
(
path
.
endsWith
(
"/"
)
?
path
+
"*"
:
path
+
"/*"
);
ServletRegistrationBean
registration
=
new
ServletRegistrationBean
(
new
WebServlet
(),
urlMapping
);
if
(
properties
.
getWebAllowOthers
())
{
registration
.
addInitParameter
(
"webAllowOthers"
,
"true"
);
H2ConsoleProperties
.
Settings
settings
=
this
.
properties
.
getSettings
();
if
(
settings
.
isTrace
())
{
registration
.
addInitParameter
(
"trace"
,
""
);
}
if
(
settings
.
isWebAllowOthers
())
{
registration
.
addInitParameter
(
"webAllowOthers"
,
""
);
}
return
registration
;
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleProperties.java
View file @
bca83bde
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -25,6 +25,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* Configuration properties for H2's console.
*
* @author Andy Wilkinson
* @author Marten Deinum
* @author Stephane Nicoll
* @since 1.3.0
*/
@ConfigurationProperties
(
prefix
=
"spring.h2.console"
)
...
...
@@ -42,10 +44,7 @@ public class H2ConsoleProperties {
*/
private
boolean
enabled
=
false
;
/**
* Allow remote access.
*/
private
boolean
webAllowOthers
=
false
;
private
final
Settings
settings
=
new
Settings
();
public
String
getPath
()
{
return
this
.
path
;
...
...
@@ -63,11 +62,37 @@ public class H2ConsoleProperties {
this
.
enabled
=
enabled
;
}
public
boolean
getWebAllowOther
s
()
{
return
webAllowOther
s
;
public
Settings
getSetting
s
()
{
return
this
.
setting
s
;
}
public
void
setWebAllowOthers
(
boolean
webAllowOthers
)
{
this
.
webAllowOthers
=
webAllowOthers
;
public
static
class
Settings
{
/**
* Enable trace output.
*/
private
boolean
trace
=
false
;
/**
* Enable remote access.
*/
private
boolean
webAllowOthers
=
false
;
public
boolean
isTrace
()
{
return
this
.
trace
;
}
public
void
setTrace
(
boolean
trace
)
{
this
.
trace
=
trace
;
}
public
boolean
isWebAllowOthers
()
{
return
this
.
webAllowOthers
;
}
public
void
setWebAllowOthers
(
boolean
webAllowOthers
)
{
this
.
webAllowOthers
=
webAllowOthers
;
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java
View file @
bca83bde
...
...
@@ -25,7 +25,6 @@ import org.junit.rules.ExpectedException;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.boot.context.embedded.ServletRegistrationBean
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
...
...
@@ -35,6 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link H2ConsoleAutoConfiguration}
*
* @author Andy Wilkinson
* @author Marten Deinum
* @author Stephane Nicoll
*/
public
class
H2ConsoleAutoConfigurationTests
{
...
...
@@ -71,6 +72,8 @@ public class H2ConsoleAutoConfigurationTests {
assertThat
(
this
.
context
.
getBeansOfType
(
ServletRegistrationBean
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getUrlMappings
())
.
contains
(
"/h2-console/*"
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getInitParameters
()).
doesNotContainKey
(
"trace"
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getInitParameters
()).
doesNotContainKey
(
"webAllowOthers"
);
}
...
...
@@ -108,17 +111,20 @@ public class H2ConsoleAutoConfigurationTests {
}
@Test
public
void
propertySetsWebAllowOthersInitParameter
()
{
public
void
customInitParameters
()
{
this
.
context
.
register
(
H2ConsoleAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.h2.console.enabled:true"
,
"spring.h2.console.web-allow-others=true"
);
"spring.h2.console.enabled:true"
,
"spring.h2.console.settings.trace=true"
,
"spring.h2.console.settings.webAllowOthers=true"
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeansOfType
(
ServletRegistrationBean
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getUrlMappings
())
.
contains
(
"/h2-console/*"
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getInitParameters
()).
containsEntry
(
"webAllowOthers"
,
"true"
);
containsEntry
(
"trace"
,
""
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getInitParameters
()).
containsEntry
(
"webAllowOthers"
,
""
);
}
}
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
bca83bde
...
...
@@ -573,6 +573,8 @@ content into your application; rather pick only the properties that you need.
# H2 Web Console ({sc-spring-boot-autoconfigure}/h2/H2ConsoleProperties.{sc-ext}[H2ConsoleProperties])
spring.h2.console.enabled=false # Enable the console.
spring.h2.console.path=/h2-console # Path at which the console will be available.
spring.h2.console.settings.trace=false # Enable trace output.
spring.h2.console.settings.web-allow-others=false # Enable remote access.
# JOOQ ({sc-spring-boot-autoconfigure}/jooq/JooqAutoConfiguration.{sc-ext}[JooqAutoConfiguration])
spring.jooq.sql-dialect= # SQLDialect JOOQ used when communicating with the configured datasource. For instance `POSTGRES`
...
...
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