application
package com.allcam.fbs;
import javax.servlet.MultipartConfigElement;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
@SpringBootApplication(exclude={RedisAutoConfiguration.class,RedisRepositoriesAutoConfiguration.class})
@ComponentScan(basePackages = {"com.allcam.*"})
@Configuration
public class Application extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
@RequestMapping("/hello")
public String index() {
return "Hello World";
}
/**
* 需要把web项目打成war包部署到外部tomcat运行时需要改变启动方式
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
/**
* 文件上传配置
*
* @return
*/
@Bean
public MultipartConfigElement multipartConfigElement()
{
MultipartConfigFactory factory = new MultipartConfigFactory();
// 单个数据大小
factory.setMaxFileSize("1024MB");
/// 总上传数据大小
factory.setMaxRequestSize("1024MB");
return factory.createMultipartConfig();
}
}
pom
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
provided
如果有servlet,还需要引入此jar包
javax.servlet
javax.servlet-api
provided
我工程的总的pom如下:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.allcam.fbs
fbs
1.0.0
war
fbs
Spring Boot base web application
org.springframework.boot
spring-boot-starter-parent
1.5.9.RELEASE
UTF-8
com.allcam.fbs.Application
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
provided
io.springfox
springfox-swagger2
2.5.0
io.springfox
springfox-swagger-ui
2.5.0
com.alibaba
fastjson
1.2.13
org.apache.commons
commons-lang3
3.1
net.sf.ehcache
ehcache-core
2.6.8
org.apache.commons
commons-collections4
4.0
org.apache.httpcomponents
httpmime
commons-io
commons-io
2.5
com.belerweb
pinyin4j
2.5.0
commons-lang
commons-lang
2.6
commons-httpclient
commons-httpclient
3.1
dom4j
dom4j
1.6.1
org.quartz-scheduler
quartz
1.8.4
javax.servlet
javax.servlet-api
provided
repo2
http://repo2.maven.org/maven2
fbs
src/main/java
src/test/java
src/main/resources
src/test/resources
org.springframework.boot
spring-boot-maven-plugin
true
maven-war-plugin
2.6
true