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
cd54e1ed
Commit
cd54e1ed
authored
Nov 26, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some more howtos
parent
94e2f907
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
2 deletions
+67
-2
howto.md
docs/howto.md
+67
-2
No files found.
docs/howto.md
View file @
cd54e1ed
...
...
@@ -7,9 +7,74 @@ the gaps later.
## Configure Tomcat
## Configure Jetty
## Test a Spring Boot Application
A Spring Boot application is just a Spring
`ApplicationContext`
so
nothing very special has to be done to test it beyond what you would
normally do with a vanilla Spring context. One thing to watch out for
though is that the external properties, logging and other features of
Spring Boot are only installed in the context by default if you use
`SpringApplication`
to create it. Spring Boot has a special Spring
`TestContextLoader`
which makes this job easy. For example (from the
JPA Sample):
```
java
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
classes
=
SampleDataJpaApplication
.
class
,
loader
=
SpringApplicationContextLoader
.
class
)
public
class
CityRepositoryIntegrationTests
{
@Autowired
CityRepository
repository
;
...
```
To use the
`SpringApplicationContextLoader`
you need the test jar on
your classpath (recommended Maven co-ordinates
"org.springframework.boot:spring-boot-starter-test"). The context
loader guesses whether you want to test a web application or not
(e.g. with
`MockMVC`
) by looking for the
`@WebAppConfiguration`
annotation (
`MockMVC`
and
`@WebAppConfiguration`
are from the Spring
Test support library).
<span
id=
"main.properties"
/>
## Externalize the Configuration of SpringApplication
A
`SpringApplication`
has bean properties (mainly setters) so you can
use its Java API as you create the application to modify its
behaviour. Or you can externalize the configuration using properties
in
`spring.main.*`
. E.g. in
`application.properties`
you might have
```
properties
spring.main.web_environment
:
false
spring.main.show_banner
:
false
```
and then the Spring Boot banner will not be printed on startup, and
the application will not be a web application.
## Create a Non-Web Application
## Create a Deployable WAR File?
Not all Spring applications have to be web applications (or web
services). If you want to execute some code in a
`main`
method, but
also bootstrap a Spring application to set up the infrastructure to
use, then it's easy with the
`SpringApplication`
features of Spring
Boot. A
`SpringApplication`
changes its
`ApplicationContext`
class
depending on whether it thinks it needs a web application or not. The
first thing you can do to help it is to just leave the web
depdendencies off the classpath. If you can't do that (e.g. you are
running 2 applications from the same code base) then you can
explicitly call
`SpringApplication.setWebEnvironment(false)`
, or set
the
`applicationContextClass`
property (through the Java API or with
[
external properties
](
#main.properties
)
). Application code that you
want to run as your business logic can be implemented as a
`CommandLineRunner`
and dropped into the context as a
`@Bean`
definition.
## Create a Deployable WAR File
Use the
`SpringBootServletInitializer`
base class, which is picked up
by Spring's Servlet 3.0 support on deployment. Add an extension of
...
...
@@ -27,7 +92,7 @@ Maven example
[
gs-war
]:
http://spring.io/guides/gs/convert-jar-to-war
## Create a Deployable WAR File for older Servlet Containers
?
## Create a Deployable WAR File for older Servlet Containers
Older Servlet containers don't have support for the
`ServletContextInitializer`
bootstrap process used in Servlet 3.0. You
...
...
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