2016-03-21 17:27:25 +08:00
= Spring Initializr image:https://badges.gitter.im/spring-io/initializr.svg[link="https://gitter.im/spring-io/initializr?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
2016-03-21 17:23:10 +08:00
2015-01-17 17:29:26 +08:00
:wiki: https://github.com/spring-io/initializr/wiki
:boot-doc: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle
:code: https://github.com/spring-io/initializr/blob/master
2013-06-06 15:40:10 +08:00
2016-06-30 19:30:00 +08:00
Spring Initializr provides an extensible API to generate quickstart projects. It also
2016-04-08 17:56:39 +08:00
provides a configurable service: you can see our default instance at
link:https://start.spring.io[]. It provides a simple web UI to configure the project
to generate and endpoints that you can use via plain HTTP.
2015-01-16 20:14:20 +08:00
2015-01-17 17:29:26 +08:00
Spring Initializr also exposes an endpoint that serves its
{wiki}/Metadata-format[meta-data] in a well-known format to allow third-party
2016-01-12 21:54:22 +08:00
clients to provide the necessary assistance.
2015-01-16 20:14:20 +08:00
2015-01-17 17:29:26 +08:00
Finally, Initializr offers a configuration structure to define all the aspects related
to the project to generate: list of dependencies, supported java and boot versions, etc. Check
the {code}/initializr-service/application.yml[configuration of our instance] for an example. Such
configuration is {wiki}/Configuration-format[also described in details on the wiki].
NOTE: We use the continuous deployment technique to manage our instance; check the
2016-04-14 22:10:59 +08:00
https://github.com/spring-io/initializr/milestones[milestones page] for an overview of changes
2015-01-17 17:29:26 +08:00
2016-04-08 17:56:39 +08:00
== Modules
Spring Initializr has the following modules:
* `initializr-generator`: standalone project generation library that can be reused in
many environments (including embedded in your own project)
* `initializr-web`: REST endpoints and web interface
* `initializr-actuator`: optional module to provide statistics and metrics on project
generation
2016-06-30 22:06:44 +08:00
`initializr-service` is an additional module that represents the production instance that
is available at link:https://start.spring.io[]. It is not enabled by default but you can
enable the `full` profile in your IDE to easily run it locally.
2016-01-12 21:54:22 +08:00
== Supported interfaces
Spring Initializr can be used as follows:
* With your browser (i.e. link:https://start.spring.io[])
* In your IDE if you are using STS or IntelliJ IDEA
* On the command-line with {boot-doc}/#cli-init[the Spring Boot CLI] or simply with [cURL] or [HTTPie]
2015-01-17 17:29:26 +08:00
2016-01-12 21:54:22 +08:00
[TIP]
====
You can "curl" an instance to get a usage page with examples (try `curl start.spring.io`)
====
== Generating a project
2015-01-17 17:29:26 +08:00
If you click on "Generate Project" on the web ui of our instance, it will download a project
archive with a Maven-based project and the necessary infrastructure to start a basic Spring
Boot app.
You could achieve the same result with a simple `curl` command
[source,bash]
----
2015-01-21 15:35:03 +08:00
$ curl https://start.spring.io/starter.zip -o demo.zip
2015-01-17 17:29:26 +08:00
----
2016-01-12 21:54:22 +08:00
The web ui exposes a bunch of options that you can configure. These are mapped to the following
request attributes:
2015-01-17 17:29:26 +08:00
* Basic information for the generated project: `groupId`, `artifactId`, `version`, `name`,
`description` and `packageName`
** The `name` attribute is also used to generate a default application name. The logic is
that the name of the application is equal to the `name` attribute with an `Application`
suffix (unless said suffix is already present). Of course, if the specified name contains
an invalid character for a java identifier, `Application` is used as fallback.
** The `artifactId` attribute not only defines the identifier of the project in the build but
also the name of the generated archive.
* `dependencies` (or `style`): the identifiers of the dependencies to add to the project. Such
identifiers are defined through configuration and are exposed in the <<meta-data,meta-data>>.
* `type`: the _kind_ of project to generate (e.g. `maven-project`). Again, each service
exposes an arbitrary number of supported types and these are available in the
<<meta-data,meta-data>>.
* `javaVersion`: the language level (e.g. `1.8`).
* `bootVersion`: the Spring Boot version to use (e.g. `1.2.0.RELEASE`).
* `language`: the programming language to use (e.g. `java`).
* `packaging`: the packaging of the project (e.g. `jar`).
* `applicationName`: the name of the application class (inferred by the `name` attribute by
default).
* `baseDir`: the name of the base directory to create in the archive. By default, the project
is stored in the root.
This command generates an `another-project` directory holding a Gradle web-based
Groovy project using the actuator:
[source,bash]
----
$ curl https://start.spring.io/starter.tgz -d dependencies=web,actuator \
-d language=groovy -d type=gradle-project -d baseDir=another-project | tar -xzvf -
----
2016-06-30 22:06:44 +08:00
NOTE: The `/starter.tgz` endpoint offers the same feature as `/starter.zip` but generates
2015-01-17 17:29:26 +08:00
a compressed tarball instead.
You could use this infrastructure to create your own client since the project is generated
via a plain HTTP call.
2015-12-31 23:44:08 +08:00
[[customize-form]]
== Customize form inputs
2016-01-05 22:48:32 +08:00
You can share or bookmark URLs that will automatically customize form inputs. For instance,
the following URL from the default instance uses `groovy` by default and set the name
to `Groovy Sample`:
2015-12-31 23:44:08 +08:00
[source,bash]
----
https://start.spring.io/#!language=groovy&name=Groovy%20Sample
----
2016-01-05 22:48:32 +08:00
The following hashbang parameters are supported: `type`, `groupId`, `artifactId`, `name`,
`description`, `packageName`, `packaging`, `javaVersion` and `language`. Review the section
above for a description of each of them.
2015-12-31 23:44:08 +08:00
2015-01-17 17:29:26 +08:00
[[meta-data]]
== Service meta-data
The service meta-data is used by the web UI and is exposed to ease the creation of
third-party clients. You can grab the meta-data by _curling_ the root
[source,bash]
----
2015-01-21 15:35:03 +08:00
$ curl -H 'Accept: application/json' https://start.spring.io
2015-01-17 17:29:26 +08:00
----
2016-01-31 18:13:14 +08:00
NOTE: As stated above, if you use `curl` without an accept header, you'll retrieve a human
readable text version of the metadata. `HTTPie` is also supported.
2015-01-21 15:35:03 +08:00
2016-01-31 18:13:14 +08:00
The meta-data basically lists the _capabilities_ of the service, that is the available
options for all request parameters (`dependencies`, `type`, `bootVersion`, etc.) The web
UI uses that information to initialize the select options and the tree of available
dependencies.
2015-01-17 17:29:26 +08:00
The meta-data also lists the default values for simple _text_ parameter (i.e. the default
`name` for the project).
NOTE: More details about the structure of the meta-data are {wiki}/Metadata-format[available
on the wiki].
== Running your own instance
2016-04-08 17:56:39 +08:00
You can easily run your own instance. The `initializr-web` modules uses Spring Boot so when it
is added to a project, it will trigger the necessary auto-configuration to deploy the service.
2015-01-17 17:29:26 +08:00
You first need to create or update your configuration to define the necessary attributes that
your instance will use. Again, check the wiki for a {wiki}/Configuration-format[description
of the configuration] and {code}/initializr-service/application.yml[review our own config] for
a sample.
You can integrate the library in a traditional Java-based project or by writing the super-simple
script below
[source,groovy]
----
package org.acme.myapp
2016-04-14 22:09:18 +08:00
@Grab('io.spring.initializr:initializr-web:1.0.0.BUILD-SNAPSHOT')
2016-04-08 17:56:39 +08:00
@Grab('spring-boot-starter-web')
2015-01-17 17:29:26 +08:00
class YourInitializrApplication { }
----
NOTE: Spring Initializr is not available on Maven central yet so you will have to build
2016-04-08 17:56:39 +08:00
it <<build,from source>> in order to use it in your own environment.
2015-01-17 17:29:26 +08:00
Once you have created that script (`my-instance.groovy`), place your configuration in the same
directory and simply execute this command to start the service:
[source,bash]
----
$ spring run my-instance.groovy
----
You may also want to <<run-app,run the default instance locally>>.
[[build]]
== Building from Source
2013-06-06 15:40:10 +08:00
2016-07-29 20:40:34 +08:00
You need Java (1.8 or better), Maven 3.2+ and a bash-like shell.
2013-06-06 15:40:10 +08:00
2015-01-17 17:29:26 +08:00
[[building]]
=== Building
2013-06-06 15:40:10 +08:00
2016-04-08 17:56:39 +08:00
Just invoke the build at the root of the project
2014-08-18 22:14:17 +08:00
2014-12-08 22:54:25 +08:00
[indent=0]
----
2015-02-17 20:52:39 +08:00
$ mvn clean install
----
If you want to run the smoke tests using Geb, you need to enable the
2016-04-08 17:56:39 +08:00
`smokeTests` profile. Firefox should also be installed on your machine:
2015-02-17 20:52:39 +08:00
[indent=0]
----
$ mvn verify -PsmokeTests
2014-12-08 22:54:25 +08:00
----
2014-08-18 22:14:17 +08:00
2015-01-17 17:29:26 +08:00
[[run-app]]
=== Running the app locally
2016-06-30 22:06:44 +08:00
Once you have <<building, built the library>>, you can easily start the app as any other
Spring Boot app from the `initializr-service` directory:
2013-06-06 15:40:10 +08:00
2014-12-08 22:54:25 +08:00
[indent=0]
----
2015-01-17 17:29:26 +08:00
$ cd initializr-service
2016-06-30 22:06:44 +08:00
$ mvn spring-boot:run
2014-12-08 22:54:25 +08:00
----
2013-06-06 15:40:10 +08:00
2013-06-07 19:26:56 +08:00
## Deploying to Cloud Foundry
2014-12-08 22:54:25 +08:00
If you are on a Mac and using http://brew.sh/[homebrew], install the Cloud Foundry CLI:
2014-03-09 01:00:59 +08:00
2014-12-08 22:54:25 +08:00
[indent=0]
----
2014-03-09 01:00:59 +08:00
$ brew install cloudfoundry-cli
2014-12-08 22:54:25 +08:00
----
2014-03-09 01:00:59 +08:00
2014-12-08 22:54:25 +08:00
Alternatively, download a suitable binary for your platform from
https://console.run.pivotal.io/tools[Pivotal Web Services].
2014-03-09 01:00:59 +08:00
2016-06-30 22:06:44 +08:00
You should ensure that the application name and URL (name and host values) are suitable for
your environment before running `cf push`.
2014-06-13 19:04:47 +08:00
2016-06-30 22:06:44 +08:00
Make sure first that the jar has been created:
2014-08-19 22:25:42 +08:00
2014-12-08 22:54:25 +08:00
[indent=0]
----
2016-06-30 22:06:44 +08:00
$ mvn package
2014-12-08 22:54:25 +08:00
----
2014-06-13 19:04:47 +08:00
2014-12-08 22:42:02 +08:00
Once the jar has been created, you can push the application:
2014-08-19 22:25:42 +08:00
2014-12-08 22:54:25 +08:00
[indent=0]
----
2016-07-17 16:08:54 +08:00
$ cf push your-initializr -p target/initializr-service.jar
2014-12-08 22:54:25 +08:00
----
2015-01-16 20:14:20 +08:00
== License
Spring Initializr is Open Source software released under the
http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license].