[@PostConstruct] 在Tomcat启动之前,会被调用,可以获取到Autowired中的内容

package com.example.demo.service;

import com.example.demo.model.Student;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class AccountService {

    @Autowired
    private Student student;

    @PostConstruct
    public void init() {
        log.info("student={}", student);
    }
}

/*
student=Student(name=xx, age=18)
 */

你可能感兴趣的:(#,springboot,java,前端,spring)