Plugging LightAdmin into your brand new application powered by Spring Boot

Please note that currently LightAdmin works for Spring Boot applications with traditional WAR packaging.

To plug LightAdmin into your application, follow the steps below:

  • Define maven dependency
    <dependency>
     <groupId>org.lightadmin</groupId>
     <artifactId>lightadmin</artifactId>
     <version>1.0.0.M3</version>
    </dependency>
  • Configure LightAdmin web-module in your SpringBootServletInitializer:
    @Configuration
    @ComponentScan
    @EnableAutoConfiguration
    @Order(HIGHEST_PRECEDENCE)
    public class LightAdminBootApplication extends SpringBootServletInitializer {
    
        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            LightAdmin.configure(servletContext)
                    .basePackage("org.lightadmin.boot.administration")
                    .baseUrl("/admin")
                    .security(false)
                    .backToSiteUrl("http://lightadmin.org");
    
            super.onStartup(servletContext);
        }
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(LightAdminBootApplication.class, args);
        }
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(LightAdminBootApplication.class);
        }
    }
    
  • Create an Administration Configuration in the package defined in basePackage property:
    public class UserAdministration extends AdministrationConfiguration<User> {
    
    public EntityMetadataConfigurationUnit configuration( EntityMetadataConfigurationUnitBuilder configurationBuilder ) {
     return configurationBuilder.nameField( "firstname" ).build();
     }
    
    public ScreenContextConfigurationUnit screenContext( ScreenContextConfigurationUnitBuilder screenContextBuilder ) {
     return screenContextBuilder
     .screenName( "Users Administration" ).build();
     }
    
    public static FieldSetConfigurationUnit listView( final FieldSetConfigurationUnitBuilder fragmentBuilder ) {
     return fragmentBuilder
     .field( "firstname" ).caption( "First Name" )
     .field( "lastname" ).caption( "Last Name" )
     .build();
     }