spring boot2.0 里的 javax.validation.Constraint 加入 service

1.ApplicationContext 静态注入

java 复制代码
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ContextAwareCfg implements ApplicationContextAware
{
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
    {
        XxxValidator.setContext(applicationContext);
    }
}
  1. 注入service
java 复制代码
import org.springframework.context.ApplicationContext;

    private static ApplicationContext context;
    protected  IDbService service;

    public XxxValidator(){
        if (context!=null)
        {
            this.service=context.getBean(IDbService .class);
        }
    }


    public static void setContext(ApplicationContext context)
    {
        XxxValidator.context = context;
    }
相关推荐
一 乐5 分钟前
家政服务管理系统|基于springboot + vue家政服务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·家政服务管理系统
碳基硅坊1 小时前
Spring AI:把大模型接进 Spring 应用
java·人工智能·spring ai
黄毛火烧雪下1 小时前
Java 核心知识点总结(一)
java·开发语言
技术小结-李爽2 小时前
【工具】Maven的下载、安装、使用
java·maven
极创信息2 小时前
Linux挖矿病毒深度清理实战教程,从进程隐藏、Rootkit驻留到彻底根除
java·大数据·linux·运维·安全·tomcat·健康医疗
努力成为AK大王2 小时前
并发编程的核心挑战、优化方案与核心知识点总结
java·开发语言·数据库
云烟成雨TD2 小时前
Agent Scope Java 2.x 系列【10】技能(Skill)
java·人工智能·agent
摇滚侠2 小时前
SpringMVC 入门到实战 DispatcherServlet 源码解读 92-95
java·后端·spring·maven·intellij-idea
键盘歌唱家3 小时前
Spring AI 入门分享:它和“直接调 API“到底差在哪
java·人工智能·spring