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

Spring boot ApplicationContext

https://www.geeksforgeeks.org/spring-applicationcontext/

  1. AnnotationConfigApplicationContext container 

对象直接标注annotation: @Configuration, @Component 

ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class, AppConfig1.class);

@ComponentScan({"controller","service","repository","pojo"})

@EnableJpaRepositories("repository")

@EntityScan("pojo")

@EnableAutoConfiguration

@Configuration

public class Config {

}

application.properties

spring.main.allow-bean-definition-overriding=true

       

  1. AnnotationConfigWebApplicationContext
public class MyWebApplicationInitializer implements WebApplicationInitializer {public void onStartup(ServletContext container) throws ServletException {AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();context.register(AppConfig.class);context.setServletContext(container);}
}
  1. XmlWebApplicationContext
public class MyXmlWebApplicationInitializer implements WebApplicationInitializer {public void onStartup(ServletContext container) throws ServletException {XmlWebApplicationContext context = new XmlWebApplicationContext();context.setConfigLocation("/WEB-INF/spring/applicationContext.xml");context.setServletContext(container);}
}
  1. FileSystemXmlApplicationContext
String path = "C:/demoProject/src/main/resources/applicationcontext/student-bean-config.xml";ApplicationContext context = new FileSystemXmlApplicationContext(path);
StudentService stuSvc= context.getBean("studentService", StudentService.class);

ClassPathXmlApplicationContext

ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext/student-bean-config.xml");
StudentService studentService = context.getBean("studentService", StudentService.class);

@Import(Config.class)
@SpringBootApplication
public static void main(String[] args) {ApplicationContext context = SpringApplication.run(DemoApplication.class, args);Student student = context.getBean(Student.class);
}

http://www.lryc.cn/news/93488.html

相关文章:

  • 【Python实战】Python采集王者皮肤图片
  • 很详细的Django开发入门详解(图文并茂)
  • Ansible 部署
  • 【操作系统】计算机操作系统知识点总结
  • springmvc整合thymeleaf
  • Redis 内存管理机制
  • Apache Zeppelin系列教程第九篇——Zeppelin NoteBook数据缓存
  • 用代码实现一个简单计算器
  • 运维圣经:挖矿木马应急响应指南
  • 【Flutter】Flutter 如何获取安装来源信息
  • Stimulsoft Reports用户手册:Report Designer介绍
  • 跨模态检索论文阅读:Dissecting Deep Metric Learning Losses for Image-Text Retrieval(GOAL)
  • 贪心算法part5 | ● 435. 无重叠区间 ● 763.划分字母区间 ● 56. 合并区间
  • IMX6ULL裸机篇之SPI实验-ICM20608代码实现
  • 51单片机读取DS18B20温度传感器
  • set/map学习
  • JavaScript Web APIs学习总结
  • 萤石摄像头RTSP流获取(黑屏解决)
  • ThreadLocal引发的内存泄漏分析
  • 银行数据治理:数据质量管理实践
  • 2.7V至25V宽输入电压15A 峰值电流
  • Vue 父子组件应用指南:从基础到实战
  • todotodo
  • 创建autotool项目
  • 计算机概念
  • 【数学建模系列】TOPSIS法的算法步骤及实战应用——MATLAB实现
  • 网络安全(黑客)工具
  • 探究前后端数据交互方式
  • Yolov5轻量化:CVPR2023|RIFormer:无需TokenMixer也能达成SOTA性能的极简ViT架构
  • Spring-Retry实现及原理