Spring MVC Webapp template generated with Maven Archetype
View the Project on GitHub dilbertside/spring-mvc-start-archetype
Demo application on Heroku. demo code
Application might be sleeping, please wait few seconds as it runs on free plan, Thank you.
The project is a Maven archetype for Spring MVC web application. It is inspired from https://github.io/kolorobot/spring-mvc-quickstart-archetype and was originally a fork. kolorobot archetype is based onto Spring Framework 5.0.x (as of January 2019)
After refactoring a bit to upgrade Spring to 5.1, the aim became to build a full Spring Framework MVC Web application only (which should not contain any Spring Boot dependencies). In that purpose some extra configuration have been added Cache, Async, WebJars, Problem.
Why?
While Spring Boot is a wonderful way to build a web application in no time, this archetype startup is a way to claim back control to all the opinionated choices made by Spring Boot team. In that way, the configuration is not hidden in Auto Configuration properties. Saying that, reading Boot code helps to build a configuration without Spring Boot. For a complete Spring Boot Application you may want to have a look to JHipster
This starter can be used for
Notes: This archetype may not work with prior versions of Spring Framework 5.0.x, or 4.3.x, and Java 1.8 It uses methods which are not reverse compatible.
When Spring Framework 5.2 will be released, a new branch to track progress will be created.
PR contributions are welcome as long as there is no Spring Boot dependency included.
A demo generated artifact is available at spring-mvc-start-archetype-demo repo
git clone https://github.com/dilbertside/spring-mvc-start-archetype-demo.git spring-mvc-webapp-demo
cd spring-mvc-webapp-demo
mvn package -Ph2
Application might be sleeping, please wait few seconds as it runs on free plan, Thank you.
A demo webapp is generated from the defaults of this archetype generator and a containerized image is built in Docker Hub
Get it running in no time with following command:
docker run -it --rm -p 8080:8080 diside/webapp
Reusing the Docker Maven repository and archetype generating project in Interactive mode
Download and use Bash generation script and run
bash generate.sh
Beware: no pom.xml should be in directory where you run following command.
docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven diside/spring-mvc-start-archetype-docker:5.1.4 mvn archetype:generate \
-DarchetypeGroupId=com.github.dilbertside \
-DarchetypeArtifactId=spring-mvc-start-archetype \
-DarchetypeVersion=5.1.11
Prerequisites: Java and Maven must be installed.
add to your ~/.m2/settings.xml a new repo in an activated profile
<repositories>
...
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
...
<repositories>
and run interactively in a directory without a pom.xml in it
mvn archetype:generate \
-DarchetypeGroupId=com.github.dilbertside \
-DarchetypeArtifactId=spring-mvc-start-archetype \
-DarchetypeVersion=5.1.11
Note: script to test generator prior to release might be useful to peruse
File > New > Project
Create from archetype
Add Archetype
buttonGroup Id
to com.github.dilbertside
Artifact Id
to spring-mvc-start-archetype
Version
to 5.1.11
Repository
to https://dilbertside.github.io/spring-mvc-start-archetype
Note: If you would like to create a project using archetype published in your local repository, skip repository field and make sure it is installed locally (see below).
File > New > Maven Project
Create a simple project
option is not selectedNext
to navigate to Select an Archetype
screenInclude snapshot archetypes
is selectedAdd Archetype
buttonArchetype Group Id
to com.github.dilbertside
Archetype Artifact Id
to spring-mvc-start-archetype
Archetype Version
to 5.1.11
Repository URL
to https://dilbertside.github.io/spring-mvc-start-archetype
OK
so the Archetype is added to the listNext
and fill in Group Id
, Artifact Id
and Version
of your new projectNote: Remember to select Include snapshot archetypes
.
To install the archetype in your local repository execute the following commands:
git clone https://github.com/dilbertside/spring-mvc-start-archetype.git
cd spring-mvc-start-archetype
mvn clean install
Use a directory without a pom.xml in it and then run:
mvn archetype:generate \
-DarchetypeGroupId=com.github.dilbertside \
-DarchetypeArtifactId=spring-mvc-start-archetype \
-DarchetypeVersion=5.1.11
Note: The above command will bootstrap a project using the archetype published in your local repository.
Docker must be installed
mvn compile jib:buildTar
docker load --input target/*.tar
docker run acme:0.0.1-dev
create a new server goto Preferences -> Server -> Runtime Environments
and add the project just created, publish, start the server
Navigate to newly created project directory (my-artifactId
) and then run:
mvn test tomcat7:run
Note: It is not recommended to run the artifact, Tomcat Maven Plugin Version 2.2 was released on 2013-11-11
http://localhost:8080/
Note: No additional services are required in order to start the application. Mongo DB configuration is in place but it is not used in the code.
Prerequisites: PostgreSQL up and running, tablespace, and credentials valid
mvn clean package -P-h2,dev,pgsql help:active-profiles
It is default DB activated, to change default reset to <activeByDefault>false</activeByDefault>
in POM
mvn clean package -P dev,h2 help:active-profiles
mvn clean package -P-h2,dev,hsql help:active-profiles
Prerequisites: MySQL up and running, tablespace, and credentials valid
mvn clean package -P-h2,dev,mysql help:active-profiles
// @EnableMongoRepositories(basePackageClasses = Application.class)
Now you can add repositories to your project:
@Repository
public interface MyRepository extends MongoRepository<MyDocument, String> {
}
This project is licensed under the MIT License - see the file for details