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
- educational purpose
- migration purpose (ie from Spring Framework core 4.3.x to 5.1.x)
- as a starting point to migrate from Spring Boot to Spring Framework core and Web MVC.
- ...
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.
- Bill of Material
- Spring MVC web application, with Java config and no Spring Boot
- Thymeleaf, Bootstrap with WebJars
- Java Persistence (JPA) ** Spring Data JPA ** Hibernate ** HSQLDB ** H2 ** Postgresql
- Testing with JUnit/Mockito
- Spring Security
- MongoDB (Spring Data Mongo)
- Docker containerization with Google Jib maven plugin
- Cache memory with Caffeine
- Email: Google mail ready
- Jackson JSON/XML/CSV data-binding functionality
- Problem, implementation of the application/problem+json draft
- Lombok to reduce boilerplate code (cf readme of generated project)
- Unit tests with JUnit 5 Jupiter and Mockito
- Localization improvements
- View.JS integration
- JDK 8 (tested with Java 11)
- Apache Maven 3.5 (tested with 3.6.0)
- Not mandatory Docker
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
Heroku Live
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
- Create new project
File > New > Project
- Click Maven on the left hand side of the new project dialog
- Check
Create from archetype
- Click the
Add Archetype
button - Set
Group Id
tocom.github.dilbertside
- Set
Artifact Id
tospring-mvc-start-archetype
- Set
Version
to5.1.11
- Set
Repository
tohttps://dilbertside.github.io/spring-mvc-start-archetype
- Click next and create the project
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).
- Create new project
File > New > Maven Project
- Make sure
Create a simple project
option is not selected - Click
Next
to navigate toSelect an Archetype
screen - Make sure
Include snapshot archetypes
is selected - Click
Add Archetype
button - Set
Archetype Group Id
tocom.github.dilbertside
- Set
Archetype Artifact Id
tospring-mvc-start-archetype
- Set
Archetype Version
to5.1.11
- Set
Repository URL
tohttps://dilbertside.github.io/spring-mvc-start-archetype
- Click
OK
so the Archetype is added to the list - Click
Next
and fill inGroup Id
,Artifact Id
andVersion
of your new project
Note: 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
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
- Build and run with the correct profile:
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
- Build and run with the correct profile:
mvn clean package -P dev,h2 help:active-profiles
- Build and run with the correct profile:
mvn clean package -P-h2,dev,hsql help:active-profiles
Prerequisites: MySQL up and running, tablespace, and credentials valid
- Build and run with the correct profile:
mvn clean package -P-h2,dev,mysql help:active-profiles
- Open MongoConfig class and uncomment the following line:
// @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