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

b2b免费发布网站大全官网自然搜索优化

b2b免费发布网站大全官网,自然搜索优化,做网站怎么开后台,青海门户网站建设各接口作用及代码示例 1. EnvironmentCapable 作用:提供对运行环境的访问,如系统属性、配置属性等。 // 配置类 Configuration public class AppConfig {Value("${app.message:Hello World}") // 默认值为Hello Worldprivate String message…

各接口作用及代码示例


1. EnvironmentCapable

作用:提供对运行环境的访问,如系统属性、配置属性等。

// 配置类
@Configuration
public class AppConfig {@Value("${app.message:Hello World}") // 默认值为Hello Worldprivate String message;
}// 使用示例
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
Environment environment = context.getEnvironment();
String appMessage = environment.getProperty("app.message"); // 获取配置属性
System.out.println("App Message: " " + appMessage); // 输出:Hello World

2. ListableBeanFactory

作用:通过名称或类型列举/查找Bean。

// 配置类
@Configuration
public class AppConfig {@Beanpublic Service service1() { return new Service("Service1"); }@Beanpublic Service service2() { return new Service("Service2"); }
}// 使用示例
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
Map<String, Service> services = context.getBeansOfType(Service.class);
System.out.println("Services: " + services.size()); // 输出:2

3. HierarchicalBeanFactory

作用:支持分层配置,允许子工厂覆盖父级属性。

// 配置父工厂
GenericApplicationContext parent = new GenericApplicationContext();
parent.refresh();// 配置子工厂并设置父级
GenericApplicationContext child = new GenericApplicationContext(parent);
child.getBeanFactory().registerSingleton("overrideBean", new OverrideBean());
child.refresh();// 获取子工厂中的Bean(优先使用子级配置)
OverrideBean bean = child.getBean(OverrideBean.class); // 使用子级的配置

4. MessageSource

作用:国际化资源管理,获取本地化消息。

// 配置类
@Configuration
public class AppConfig {@Beanpublic MessageSource messageSource() {ResourceBundleMessageSource source = new ResourceBundleMessageSource();source.setBasename("messages"); // 国际化文件名return source;}
}// 使用示例
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
String greeting = context.getMessage("greeting", null, Locale.US); // 从messages.properties获取
System.out.println("Greeting: " + greeting); // 输出:Hello!

5. ApplicationEventPublisher

作用:发布应用事件,支持事件监听机制。

// 自定义事件
public class CustomEvent extends ApplicationEvent {public CustomEvent(Object source, String data) {super(source);this.data = data;}private String data;
}// 监听器
@Component
public class EventListener implements ApplicationListener<CustomEvent> {@Overridepublic void onApplicationEvent(CustomEvent event) {System.out.println("Received event: " + event.getData());}
}// 发布事件
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
context.publishEvent(new CustomEvent(this, "Event occurred!")); // 触发监听器

6. ResourcePatternResolver

作用:通过通配符解析资源路径。

// 使用示例
ApplicationContext context = new ClassPathXmlApplicationContext();
Resource[] resources = context.getResources("classpath*:/*.properties");
for (Resource resource : resources) {System.out.println("Found resource: " + resource.getFilename()); // 输出所有匹配的文件名
}

接口功能对比表格

接口名称核心功能关键方法典型使用场景
EnvironmentCapable访问系统/配置环境属性getEnvironment()读取配置文件或系统属性
ListableBeanFactory按名称/类型查找BeangetBeansOfType()动态获取所有实现类Bean
HierarchicalBeanFactory支持分层配置覆盖setParentBeanFactory()多环境配置继承与覆盖
MessageSource国际化消息解析getMessage()多语言提示信息管理
ApplicationEventPublisher发布应用事件publishEvent()实现事件驱动架构
ResourcePatternResolver通配符资源路径解析getResources()批量加载配置文件或静态资源

总结

  • EnvironmentCapable:环境属性访问,如读取application.properties
  • ListableBeanFactory:动态查找Bean,适合需要按类型聚合的场景。
  • HierarchicalBeanFactory:分层配置,适用于多环境部署。
  • MessageSource:国际化支持,如多语言应用。
  • ApplicationEventPublisher:事件驱动,解耦组件间通信。
  • ResourcePatternResolver:批量加载资源,如扫描所有配置文件。
http://www.dtcms.com/wzjs/322105.html

相关文章:

  • 做网站月入100万外媒头条最新消息
  • 网站搜索引擎推广怎么做查关键词
  • 中国建设银行快捷付授权网站网站排名优化快速
  • 做网站是那个语言写的太原网站建设谁家好
  • scratch编程免费下载seo诊断书
  • 怎么做自己的优惠券网站b2b平台
  • 发票项目网站建设费百度有什么办法刷排名
  • wordpress 新闻列表厦门网站优化
  • 在谷歌上做英文网站网络广告电话
  • 安徽网站建设SEO优化制作设计公司网络营销的常用方法有哪些
  • iis默认网站 建设中怎么做百度搜索排名
  • 上海品牌网站设计seo团队
  • 北京网站建设技术推广普通话文字素材
  • 网络域名是什么seo优化网站推广全域营销获客公司
  • 最权威的做网站优化价格网站建设营销型
  • 金坛做网站公司技术培训平台
  • 成都网页设计的网站建设手机网站seo免费软件
  • 全国最大的网站建设公司可以商用的电视app永久软件
  • 做策划常用的网站seo网站搜索优化
  • 泰州网站建设搭建抖音seo排名
  • 网站两边横幅怎么做营销网络的建设
  • 贵州定制型网站建设郑州谷歌优化外包
  • 网站策划与建设连云港seo优化公司
  • 雷州网站去了外包简历就毁了吗
  • 国外推广网站中国万网域名注册服务内容
  • 营销型网站的分类关键词调整排名软件
  • 淮安做网站友链出售
  • 网站域名做链接怎么做360优化大师旧版本
  • 如何用一个域名做多个网站搜索引擎广告形式有
  • 用jquery做的网站百度云建站