Skip to content

rekhamitt/Spring-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Example 1.0

This is a skeleton project using spring.

The main idea behind this is to have a working java spring web and/or rest application up and running as quick as possible, seeing as creating a new java project is usually a very time consuming process.

Everything should be completely automatic with the exception of the mysql database creation. Default database name is "example". It can be change in application.properties.

spring.datasource.url = jdbc:mysql://localhost:3306/example
spring.datasource.username = root
spring.datasource.password =

So far, the project includes:

There is one drawback of using .JAR: since we are using classpath to serve our templates to Thymleaf, we lose the ability to change the .html files during runtime for testing purposes. We need to deploy the files again.

**TODO: test docker support. https://spring.io/guides/gs/spring-boot-docker/ **

**TODO: Test tests support: http://www.jayway.com/2014/07/04/integration-testing-a-spring-boot-application/ **

####REMOVE WEB CONTENT: If you don't need a WEB Application:

    1. Delete the folder webapp/webpages AND webapp/templates. You will then use thymeleaf only for email templates.
    1. If you want absolutely NOTHING to do with HTML and WEB pages:
  • Delete the webapp folder entirely

  • Remove ThymeleafConfig.java

  • Remove "Security configuration for web content" in SecurityConfig.java and change the security configurations to your liking

  • Delete Controllers' WEB folder

  • Remove LocalizationConfig.java and the resources/i18n folder

  • Remove MailerService.java

  • Remove thymeleaf configurations from application.properties

  • Remove all Thymeleaf AND WebJar dependencies from pom.xml

  • Remove the compiler and minifier plugins from pom.xml (both CoffeScript and SCSS)

  • Remove this resource from pom.xml:

       <resource>
           <directory>${basedir}/src/main/webapp</directory>
           <filtering>false</filtering>
           <excludes>
             <!-- These file are excluded because they are compiled and minified by other plugins -->
             <exclude>**/*.coffee</exclude>
             <exclude>**/*.scss</exclude>
           </excludes>
       </resource>

####RUN AS WAR: You can also run this application as a .WAR with an external Tomcat. All you have to do is:

     <!-- WebApp Resources-->
     <resource>
       <directory>${basedir}/src/main/webapp</directory>
       <filtering>false</filtering>
       <excludes>
         <exclude>webpages/</exclude>  <!-- <--------- THIS LINE HERE -->
         <!-- These file are excluded because they are compiled and minified by other plugins -->
         <exclude>**/*.coffee</exclude>
         <exclude>**/*.scss</exclude>
       </excludes>
     </resource>
    1. Remove this configuration from ThymeleafConfig.java
      @Bean
      public ClassLoaderTemplateResolver webpagesClassLoaderResolver() {
        ClassLoaderTemplateResolver webpagesResolver = new ClassLoaderTemplateResolver();
        webpagesResolver.setTemplateMode("HTML5");
        webpagesResolver.setPrefix("webpages/");
        webpagesResolver.setSuffix(".html");
    
        return webpagesResolver;
      }
    1. Add this configuration to ThymeleafConfig.java
      @Bean
      public ServletContextTemplateResolver webpagesServletContextResolver() {
        ServletContextTemplateResolver webpagesResolver = new ServletContextTemplateResolver();
        webpagesResolver.setTemplateMode("HTML5");
        webpagesResolver.setPrefix("/webpages/");
        webpagesResolver.setSuffix(".html");
    
        return webpagesResolver;
      }
    1. Add this plugin in pom.xml
     <!-- Since we copy web files into classpath to make then available for spring and thymeleaf,
     these exclusions avoid duplications of webapp content when packaging a war. -->
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-war-plugin</artifactId>
       <configuration>
         <packagingExcludes>mails/,resources/,templates/</packagingExcludes>
       </configuration>
     </plugin>

###WARNING: Thymeleaf sec:authorize tags are not working with Spring Security 4 for now. Waiting for the release of Spring-Boot 1.3 that might fix it.

####WARNING 2: KEYSTORE IS INVALID. PLEASE CREATE ONE TO SUBSTITUTE.

About

Extensive Spring Example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published