I have a data structure representing a CSV file containing thousands of config settings. The structure is a Java class file with instance variables to represent the records in the file (ie: a HashMap) and the state of the file (errors, warnings, etc).
These classes are not created by Spring as they have state. I would like the class to access system configuration properties which are currently handled by a Spring managed database DAO class. Usually when classes need this DAO I inject it through Spring using @Autowired. But as my data structure is not managed by Spring, how can the CSV structure class access the DAO?
The only method I can think of is when creating the data structure from the Spring managed bean to just pass in the DAO:
CSVDataStruture c = new CSVDataStruture(dao);
What makes you think that Spring cannot / should not create objects that have state?
Depending on what you are trying to do (it is hard to figure this out!) I would do one of the following:
Give the CSV class getters and setters for a CVS file parameter and a DAO parameter, and instantiate it using Spring DI. This assumes that the filename is available when Spring wiring occurs.
Create a factory class with a method that instantiates a CSV object from a file parameter. The factory class should have a getter/setter for the DAO object and be instantiated using Spring DI.