All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.javalib.isb.AutoConfig Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha-8
Show newest version
package net.javalib.isb;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Properties;
import com.codahale.metrics.MetricRegistry;
import com.ryantenney.metrics.spring.config.annotation.EnableMetrics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@ComponentScan
@EnableMetrics
public class AutoConfig {
    private static final Logger logger = LoggerFactory.getLogger(AutoConfig.class);

    public AutoConfig() {
        logger.info("ISB AutoConfig ON");
    }


    @Bean
    WebMvcConfigurerAdapter webMvcConfigurerAdapter(final @Value("${isb.swagger:true}") boolean enableSwagger, final MetricRegistry metricRegistry) {
        WebMvcConfigurerAdapter config = new WebMvcConfigurerAdapter() {

            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                if (enableSwagger) {
                    registry.addResourceHandler("/swagger/**").addResourceLocations("classpath:/isb-swagger/");
                }
            }

        };
        return config;
    }

    @Autowired
    public void setInfoProperties(ConfigurableEnvironment env) {
        Properties props = new Properties();
        RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        props.put("info.isb.startTime",runtimeBean.getStartTime());
        env.getPropertySources().addFirst(new PropertiesPropertySource("extra-info-props",props));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy