【问题标题】:spring custom scan in msf4jmsf4j中的spring自定义扫描
【发布时间】:2017-01-17 10:02:47
【问题描述】:

我在包 com.a.sample1 中有一个 msf4j 应用程序,我想扫描 com.a.sample2 中的一些组件。有没有办法在 msf4j 中做到这一点?我正在使用:

public static void main(String[] args) {
    MSF4JSpringApplication
            .run(Application.class, args);
}

我无法将我的应用程序放入 com.a 包中以自动扫描 sample1 和 sample2,原因之一是 com.a.sample2 来自某个外部库。

在 Spring Boot 中,如果组件、JPA Repositories 或 Entities 不在 Application.java 包的子包中,那么我们需要明确指定它们。这在 MSF4J 中是否可能?

【问题讨论】:

    标签: msf4j wso2msf4j


    【解决方案1】:

    虽然我仍在等待扫描包而不是应用程序包的答案,但有解决方法。我创建了一个注释,并在该注释中导入了配置类。

    因此,当您在 sample2 中添加注释(在 sample1 中创建)时,它将从 sample1 导入配置并将 bean 加载到 sample2。

    【讨论】:

      【解决方案2】:

      我检查了 MSF4J 源代码,发现仅针对 Application 类的包开始扫描,作为第一个参数传递给 run 方法:https://github.com/wso2/msf4j/blob/release-2.1.0/spring/src/main/java/org/wso2/msf4j/spring/MSF4JSpringApplication.java#L165

      不幸的是,它是私有方法,您无法更改它。 另一方面,“source”参数(运行方法中使用的第一个参数)仅用于确定包自动扫描 - 因此,您可以简单地将任何 DummyClass 放入 com.a 包中并通过以下方式运行它:

      MSF4JSpringApplication
                  .run(DummyClass.class, args);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-22
        相关资源
        最近更新 更多