Giter Site home page Giter Site logo

tkajen / minimal-boot-actuator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pytry/minimal-boot-actuator

0.0 2.0 0.0 192 KB

A Spring Boot application with minimal boot configuration, showing how to convert an older spring application to spring boot.

Java 100.00%

minimal-boot-actuator's Introduction

minimal-boot-actuator

A Spring Boot application with minimal boot configuration. Shows how to convert an older spring application to spring boot. Original source: http://www.mkyong.com/spring-mvc/gradle-spring-mvc-web-project-example/

Conversion Process

  • Add a Java Configuration file annotated with @SpringBootApplication
    package llc;
	
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.context.web.SpringBootServletInitializer;

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
    }
  • Add the Application configuration file as a bean to the traditional xml configuration ( added it just after the context scan).
    <bean name="applicationConfiguration" class="llc.Application"/>
  • Move view resolvers into Application java configuration.
    @Bean
    public InternalResourceViewResolver internalResourceViewResolver() throws ClassNotFoundException {
        InternalResourceViewResolver view = new InternalResourceViewResolver();
        view.setViewClass(JstlView.class);
        view.setPrefix("/WEB-INF/view/jsp/");
        view.setSuffix(".jsp");
        
        return view;
    }

Alternatively, if you can decide add the prefix and suffix to application.properties. You can then inject them with @Value in your application, or delete it entirely and just use the provided spring boot view resolver. I went with the former.

  • Removed Default context listener from the spring context xml.

This is important! Since spring boot will provide one you will get an "Error listener Start" exception if you do not.

    <!-- This was removed from web.xml
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>
    -->
  • Add the plugin to your build script dependancies (I was using gradle)
    buildscript{
        repositories {
            mavenLocal()
            mavenCentral()
        }
        dependencies{
            classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE'
        }
    }
  • Add a mainClassName property to the build file, and set to an empty String (indicates not to create an executable).
    mainClassName=''
  • Modify dependacies for spring boot actuator
    dependencies {
    
        compile("org.springframework:spring-webmvc:4.1.6.RELEASE")
        compile("jstl:jstl:1.2")
        compile("org.springframework.boot:spring-boot-starter-actuator")
    
        //include in compile only, exclude in the war
        providedCompile("javax.servlet:servlet-api:2.5")
        providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    }

minimal-boot-actuator's People

Contributors

pytry avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.