当前位置: 首页 > news >正文

建设网站需要什么基础seo推广

建设网站需要什么基础,seo推广,网络舆情处置公司,优酷视频上传网站源码在服务启动时,做一些操作,比如加载配置,初始化数据,请求其他服务的接口等。 有三种方法: 第一种是实现CommandLineRunner接口 第二种是实现ApplicationRunner接口 第三种是使用注解:PostConstruct 三者使用…

在服务启动时,做一些操作,比如加载配置,初始化数据,请求其他服务的接口等。
有三种方法:

第一种是实现CommandLineRunner接口
第二种是实现ApplicationRunner接口
第三种是使用注解:@PostConstruct
三者使用方法
先看下三种方法分别怎么实现我们的目的

CommandLineRunner
CommandLineRunner执行的时间节点是在Application完成初始化工作之后。

CommandLineRunner在有多个实现的时候,可以使用@order注解指定执行先后顺序。、

使用方法:实现CommandLineRunner接口,并重写run方法,run方法里写我们的初始化操作。

示例:

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;


@Component
public class InitTest02 implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        System.out.println("========CommandLineRunner");
    }
}

ApplicationRunner
ApplicationRunner跟CommandLineRunner是区别是在run方法里接收的参数不同,CommandLineRuner接收的参数是String… args,而ApplicationRunner的run方法的参数是ApplicationArguments 。

实现ApplicationRunner接口,并重写run方法,run方法里写我们的初始化操作。

示例:

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;


@Component
public class InitTest01 implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("=======ApplicationRunner");
    }
}

@PostConstruct
@PostConstruct是在对象加载完之后执行。

使用@PostConstruct注解再自己写的方法上,方法内写初始化逻辑

示例:

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;


@Component
public class InitTest03 {

    @PostConstruct
    public void start() {
        System.out.println("========PostConstruct");
    }
}

三者区别
三者都可以实现项目启动前的一些初始化操作,唯一不同的是初始化的时间不同。

Spring应用启动过程中,肯定是要自动扫描有@Component注解的类,加载类并初始化对象进行自动注入。加载类时首先要执行static静态代码块中的代码,之后再初始化对象时会执行构造方法。

在对象注入完成后,调用带有@PostConstruct注解的方法。当容器启动成功后,再根据@Order注解的顺序调用CommandLineRunner和ApplicationRunner接口类中的run方法。

因此,加载顺序为static>constructer>@PostConstruct>CommandLineRunner和ApplicationRunner。

http://www.dinnco.com/news/16870.html

相关文章:

  • 上海中国建设银行招聘信息网站如何做免费网络推广
  • html5网站带后台广州最新发布最新
  • 怎么创立一个自己的品牌seo产品是什么意思
  • 杭州 建设网站首页推广运营是做什么的
  • seo做的最好的网站排行360广告联盟平台
  • 微企业网站模板免费营销网页
  • 一款可做引流的网站源码东莞seo顾问
  • 黄页推广软件网站怎么做产品推广和宣传
  • 南雄市建设局网站seo是什么部位
  • 大连网站制作公司58免费制作网页平台
  • 做公益做的好的的网站我赢网客服系统
  • 专业医疗建站友情链接还有用吗
  • 旅游网站开发毕业论文前言产品网络营销分析
  • 网站栏目结构包括哪些地推是什么
  • 威联通怎么建设网站淘宝店铺推广方法
  • 大型网站建设企业名录模板苏州网站
  • 安徽网站建设详细教程国外网站排名前十
  • 手机网站 标题长度网站seo视频
  • 企业网站主要有哪四种类型设计网页的软件
  • 网站推广策划的思路包括哪些用广州seo推广获精准访问量
  • 深圳微信建网站seo推广视频隐迅推专业
  • 做vip电影网站站内优化主要从哪些方面进行
  • 付网站首期合同款怎么做分录重庆seo和网络推广
  • 网站制作公司多少人十八大禁用黄app入口
  • 网站开发作业代做上海百度推广优化
  • 新疆生产建设兵团12师网站武汉seo服务多少钱
  • 做网站基础教程优化营商环境存在问题及整改措施
  • 找电商平台帮我卖产品seo优化网络公司
  • 商务型网站有哪些免费网络项目资源网
  • 末备案网站如何做cdn营销型网站建设方案