The project is a Maven archetype for Spring MVC web application.
- No-xml Spring MVC web application
- Thymeleaf, Bootstrap
- JPA (Hibernate/HSQLDB/Spring Data JPA)
- JUnit/Mockito
- Spring Security
- MongoDB (Spring Data Mongo)
- JDK 8 (tested with Java 11)
- Maven 3 (tested with 3.6.0)
mvn archetype:generate \
-DarchetypeGroupId=pl.codeleak \
-DarchetypeArtifactId=spring-mvc-quickstart \
-DarchetypeVersion=5.0.1 \
-DgroupId=my.groupid \
-DartifactId=my-artifactId \
-Dversion=version \
-DarchetypeRepository=http://kolorobot.github.io/spring-mvc-quickstart-archetypeNote: The above command will bootstrap a project using the archetype published here: http://kolorobot.github.io/spring-mvc-quickstart-archetype
Navigate to newly created project directory (my-artifactId) and then run:
mvn test tomcat7:runNote: I do not recommend this way of running 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.
- 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 Archetypebutton - Set
Group Idtopl.codeleak - Set
Artifact Idtospring-mvc-quickstart - Set
Versionto5.0.1 - Set
Repositorytohttp://kolorobot.github.io/spring-mvc-quickstart-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 projectoption is not selected - Click
Nextto navigate toSelect an Archetypescreen - Make sure
Include snapshot archetypesis selected - Click
Add Archetypebutton - Set
Archetype Group Idtopl.codeleak - Set
Archetype Artifact Idtospring-mvc-quickstart - Set
Archetype Versionto5.0.1 - Set
Repository URLtohttp://kolorobot.github.io/spring-mvc-quickstart-archetype - Click
OKso the Archetype is added to the list - Click
Nextand fill inGroup Id,Artifact IdandVersionof your new project
Note: Remember so select Include snapshot archetypes.
If you have any troubles with installation in Eclipse, you may want to have a look at this issue: #74
To install the archetype in your local repository execute the following commands:
git clone https://github.com/kolorobot/spring-mvc-quickstart-archetype.git
cd spring-mvc-quickstart-archetype
mvn clean installCreate a new empty directory for your project and navigate into it and then run:
mvn archetype:generate \
-DarchetypeGroupId=pl.codeleak \
-DarchetypeArtifactId=spring-mvc-quickstart \
-DarchetypeVersion=5.0.1 \
-DgroupId=my.groupid \
-DartifactId=my-artifactId \
-Dversion=versionNote: The above command will bootstrap a project using the archetype published in your local repository.
- Add dependency to PostgreSQL driver in POM:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1207</version>
</dependency>
- Change
persistence.properties:
dataSource.driverClassName=org.postgresql.Driver
dataSource.url=jdbc:postgresql:postgres
dataSource.username=postgres
dataSource.password=postgres
hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
hibernate.hbm2ddl.auto=create
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.use_sql_comments=true
- 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> {
}