首页 > 解决方案 > 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();
    }
}

标签: springjavabeansjava-module

解决方案


推荐阅读