h2so4
V2EX  ›  问与答

关于 Java 项目整合到 Spring 的疑问

  •  1
     
  •   h2so4 · Jun 4, 2019 · 1212 views
    This topic created in 2724 days ago, the information mentioned may be changed or developed.

    是这样的,楼主基于 aspectj 封装了一个通用模块,作为一个 jar 工程单独打包,现在有一个想法就是,这个模块我希望完全不依赖 spring,但是呢,这个模块同样可以在一个 spring 工程中引入使用。

    因为对这方面不太了解,想请教下 dalao 们,这样做是否有问题,如果接入 spring 的话,一些类就需要添加 @Component 注解了吧,不添加的话,是否会造成调用一次生成一次实例的问题?(就是无法保证是单例)

    这块了解的不多,不知道有没有偏差,请教一下大佬们

    2 replies  •  2019-06-04 23:45:03 +08:00
    c4f36e5766583218
    c4f36e5766583218
    Jun 4, 2019
    1
    xml 配置?
    MoHen9
    MoHen9
    Jun 4, 2019 via Android
    2
    分成两部分,核心模块不引入 spring,平时该怎么用就怎么用,另一模块是专门为 spring 提供配置的,写个 configuration,加个 @EnableAutoxxxx 注解,需要时直接使用注解,可以参考其他的框架,比如 mybatis 在 spring boot 中的集成。

    其实不用纠结是否是单例。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2337 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:14 · PVG 21:14 · LAX 05:14 · JFK 08:14
    ♥ Do have faith in what you're doing.