对非bean类使用application.properties

dtcbnfnu  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(289)

我有以下不是SpringBean的类:

  1. public class NotBean implements NotBeanInterface {
  2. @Override
  3. public void relevantMethod() {
  4. System.out.println(Config.CONSTANT); // some value, enum or static
  5. }
  6. }

还有下面的SpringBean,它使用了上述方法:

  1. @Service
  2. public class FooBean {
  3. public void foo() {
  4. new NotBean().relevantMethod();
  5. }
  6. }

一切都很好,但事实证明有多种环境。为了生产,我需要 Config.CONSTANT 平等 10 . 对于另一个环境我需要它 20 .
因此,我考虑将这个配置从enum/static移到 application.properties .
问题是,我不能使用 application.properties 在一个 NotBean 非bean类。
这种情况似乎很平常,该如何处理?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题