spring - Spring从模块加载和使用bean
问题描述
我将我的项目分为 3 个模块 - 客户端、服务器和核心。在核心模块中,我定义了哨兵所需的设置。我想在客户端和服务器模块中使用这些 bean,这样我就不必为每个模块重新定义它们。
可能吗?如果有,请举例。
我当前在核心模块中的哨兵设置。
org/project/core/configurations/SentryConfiguration.java
package org.project.core.configurations;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
@Configuration
public class SentryConfiguration {
/*
This class is constructed according official sentry documentation.
URL: https://docs.sentry.io/platforms/java/guides/spring/
*/
@Bean
public HandlerExceptionResolver sentryExceptionResolver() {
return new io.sentry.spring.SentryExceptionResolver();
}
@Bean
public ServletContextInitializer sentryServletContextInitializer() {
return new io.sentry.spring.SentryServletContextInitializer();
}
}
解决方案
推荐阅读
- swift - 将 UIAlert 的结果返回给委托方法
- c# - 如何防止我的 ASP.NET MVC 应用程序想要在 Google OAuth 之后注册用户?
- java - 使用 ModelMapper 反序列化 Json 时如何修复错误 START_ARRAY 令牌?
- typescript - 类型的泛型参数的打字稿推断不可分配
- html - 在 RMarkdown 中的 HTML 模板中渲染 ggplot2 绘图
- javascript - 如何解决生产中 react-admin 请求中的“CORS failed”错误?
- flutter - 如何解决 Flutter 中导入 FontAwesome 时出错的问题
- java - Jnlp 应用程序未完全签名
- reactjs - React + Mui v5:我需要为 sx 道具使用 StyledEngineProvider 吗?
- python - 你如何遍历多个谷歌搜索并抓取第一个结果?