java - 在哪里应用 ApplicationContextAware
问题描述
我有一个服务类,它是一个 spring bean,我想在一个不是 spring bean 的类(A 类)中使用这个服务类。
我应该在哪里实现 ApplicationContextAware ?
以下是我的代码
@Service("sharedListsService")
public class SharedListsService
{
}
public class A
{
// I want to call my service class methods here
}
解决方案
ApplicationContextAware仅适用于 spring bean。它将应用程序上下文注入到 bean 中。这就是为什么您不能直接使用它来将 SharedListsService 的实例放入“A”。您需要一个 bean,可能是“A”的工厂来为您接线。
推荐阅读
- mysql - MySQL 服务器:如何在没有“Workbench”的情况下安装?
- c# - 如何从 MVVM 中的选定项访问模型?
- javascript - 将文件添加到 Dropzone 会冻结 Firefox (v61)
- parsing - HANA:使用小数秒将字符串解析为时间戳
- jquery - DataTable 实例获取 HTML 元素 ID
- mysql - MySQL:4 表迁移到 1 表
- solr - 在 Spring Boot 中使用 solrj 以 xlsx 形式获得响应
- sql - 基于另一个表更新一个表
- swift - textViewDidChange 函数没有响应
- java - java中将不同类型的数据序列化成ORC格式