Announcement Announcement Module
No announcement yet.
Generating spring beans within the application Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating spring beans within the application

    I have a spring application, where the function of one of the components is to read multiple files on disk and produce data objects that are then used elsewhere in the app. It will read multiple files and produce multiple data objects.

    The design I have been given states that the data object should be created by the spring factory, implimenting an interface.

    The easiest way to do this would just have the component aquire/create a beanfactory and use getbean, with the data bean configured as prototype. However that strikes me as poor OO as it has tightly coupled my component to the spring container.

    what is the recomended way of solving this? I want to have spring configured data objects, but I want to avoid coupling the component that creates them strongly to the spring framework.

  • #2
    I'm afraid the problem is unclear. Am I right thinking that you want to create many objects where every such object has many properties and part of the properties is filled by the processed data and you want another part to be configured by spring? If so you can exploit @Configurable Spring facility - 6.8.1. Using AspectJ to dependency inject domain objects with Spring


    • #3

      Create many objects, each of which has many properties, currently likely that none of these properties will be configured by Spring, the main reason the design has Spring generate the class was for ease of mocking the object for Unit testing.

      Though your answer has made me question using spring to generate the object at all - given it is not being configured by the spring container just using a constructor seems more sensible. I may not be able to mock it but the file reading component is not coupled to the spring framework.