import java.lang.reflect.Method;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
public class TestServiceImpl implements TestService,ApplicationListener<ContextRefreshedEvent> {
@Resource
LuruWordService luruWordService;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
System.out.println("------初始化执行 这里把所有的接口都遍历一遍 存到权限表里面----");
try {
// 获取上下文
ApplicationContext context = event.getApplicationContext();
// 获取所有beanNames
String[] beanNames = context.getBeanNamesForType(Object.class);
for (String beanName : beanNames) {
Controller conClass = context.findAnnotationOnBean(beanName,Con
初始化执行 这里把所有的接口都遍历一遍 存到权限表里面
最新推荐文章于 2022-01-27 17:40:11 发布
本文介绍了一种在Spring Boot应用程序启动时,通过监听`ContextRefreshedEvent`事件,遍历所有`@Controller`注解的类和`@RequestMapping`注解的方法,从而获取接口信息并批量存入权限表中的方法。这样避免了每次新增接口时手动维护数据库记录的繁琐过程。
摘要由CSDN通过智能技术生成