springBoot(一)
来源:互联网 发布:什么是主域名与子域名 编辑:程序博客网 时间:2024/06/06 00:23
1.SpringBoot的启动类
@SpringBootApplicationpublic class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}启动后,默认的tomcat端口是8080,可以进行自定义端口
@Beanpublic EmbeddedServletContainerFactory getServletContainer(){TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();factory.setPort(8001);factory.setSessionTimeout(10, TimeUnit.MINUTES);factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notFound.html"));return factory;}配置端口,还可以配置无法访问的路径页面
@SpringBootApplication(scanBasePackages = { "com.example.xxx", "com.example.xxx"})@EnableSpringHttpSessionpublic class DemoApplication extends WebMvcConfigurerAdapter { public static void main(String... args) { SpringApplication springApplication = new SpringApplication(WebAnalysisRestApplication.class); springApplication.run(args); } @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charset.forName("UTF-8")); List<MediaType> supportedMediaTypes = Lists.newArrayList(); supportedMediaTypes.add(MediaType.parseMediaType("application/json;charset=UTF-8")); stringConverter.setSupportedMediaTypes(supportedMediaTypes); stringConverter.setWriteAcceptCharset(false); converters.add(stringConverter); }}
继承了webMvcConfigurerAdapter,重写了configureMessageConverters方法,定制了http的消息转换,http输入请求将消息转为java实体类,输出请求是转成json格式,将字符集设置为utf-8
@SpringBootApplication注解的scanBasePackages,自动扫描路径下的所有Bean
@EnableSpringHttpSession 基于session的管理
@EnableTransactionManagement 基于事务的管理,一般用于启动service层,在操作数据库的service类或方法上加上@Transactional
@EnableScheduling 基于定时任务的管理,在方法前加上@Scheduled即可实现定时任务
阅读全文
0 0
- SpringBoot 一
- SpringBoot(一)
- springBoot(一)
- SpringBoot一
- SpringBoot笔记一
- springboot学习笔记(一)
- SpringBoot学习篇一
- springboot(一)概述
- SpringBoot学习笔记(一)
- SpringBoot入门一
- SpringBoot学习一
- SpringBoot(一)
- springBoot 学习(一)
- springboot使用(一)
- SpringBoot笔记一
- SpringBoot笔记一
- Springboot(一):入门篇
- 一、SpringBoot精要
- Java算法面试题(004) 实现一个算法来确定一个字符串是否具有所有唯一的字符
- MySQL数据库中tinyint类型字段读取数据为true和false
- Chrome调试js经常出现的问题集合
- 9个最重要的生活态度
- Java的原子类
- springBoot(一)
- 解决@ResponseBody注解返回中文乱码
- 3D扫描仪到底是怎么工作的?
- POJ 1159.Palindrome
- 前端页面Double转换Integer,input前段页面的类型转换
- Python全局变量和局部变量
- Spring boot Hibernate SSerializationException: could not deserialize invalid stream header
- 用select实现TCP回射程序(服务器及客户端)
- SQL Server2008 学习之(十二) :XML存储与查询技术