package com.suncht.gda;
import javax.servlet.Filter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner.Mode;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
/**
* 静态资源服务
* @author changtan.sun
*
*/
@Configuration
@SpringBootApplication(exclude = { MongoDataAutoConfiguration.class, MongoAutoConfiguration.class, JmsAutoConfiguration.class, RedisAutoConfiguration.class })
public class GdaStaticResourceApplication {
protected final static Logger logger = LoggerFactory.getLogger(GdaStaticResourceApplication.class);
@Bean
public Filter characterEncodingFilter() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
return characterEncodingFilter;
}
/**
* mvn打包后,需要指定内嵌tomcat的服务,否则会“找不到EmbeddedServletContainerFactory”报错
* 也可以使用jetty服务
* @return
*/
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
return factory;
}
public static void main(String[] args) {
SpringApplication application = new SpringApplication(GdaStaticResourceApplication.class);
application.setBannerMode(Mode.OFF);
application.run(args);
logger.info("通用数据采集系统-静态资源服务启动成功!");
System.out.println("通用数据采集系统-静态资源服务启动成功!");
}
}
复用代码系列:SpringBoot的Application类通用写法
最新推荐文章于 2024-04-22 03:56:52 发布