我正在构建一个可供 Spring Boot 和 J2EE 应用程序使用的通用 jar
我有一个公共项目,我想导入到 Spring Boot 应用程序和 J2EE 应用程序中。其中一个对象是一组由参数设置的属性。在 Spring Boot 中,我想使用 @Value 来设置它们,对于非 Spring 平台,我必须使用代码加载属性。我想在两种环境中使用相同的对象,因为它的使用很普遍。我尝试使用构建器失败了,因为它们不可避免地在 spring 对象之前被实例化。
这是谁干的?
提前致谢
I have a common project I'd like to import to both a spring boot application and a J2EE application. One of the Objects is a set of attributes set from parameters. In spring boot I'd like to use @Value to set them, for the non-spring platform I have to load the properties with code. I'd like to use the same object for both environments since it's use is pervasive. My attempts to use builders have failed because they inevitably get instantiated before the spring objects.
Who's done this?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我本来希望有更优雅的东西,但也许我被 Spring Boot 宠坏了。我必须用实现 ApplicationContextAware 的构建器替换 @Autowired 参数类。如果 setApplicationContext 方法被执行(构建器类由 Spring 加载并且是感知的),或者通过简单检索非 Spring 环境的参数,则该方法将实例化参数对象。
I'd hoped for something more elegant but maybe I'm spoiled by Spring Boot. I had to replace the @Autowired parameters class with a builder that implements ApplicationContextAware. The setApplicationContext method will instantiate the parameters object if it gets executed (the builder class was loaded by Spring and is aware) or by the simple retrieval of parameters for a non-spring environment.