Announcement Announcement Module
Collapse
No announcement yet.
Newbie question - understanding the value of Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie question - understanding the value of Spring

    We have a web app at work that employs a number of services, sucha s security/permissions for table/row access, os registry access, os ini file access, etc..

    We have implemented these globally using services as either application (tomcat application) context objects or static methods in a class.
    For our purposes, these objects only access session scoped varialbes. Since this is the case, there is never a concern about synchronization of access.

    My question is why would Spring dependency injection be a better model for access to these services than simple static method calls?

  • #2
    If your objects don't have any configuration files, or access any external singleton services, use data access APIs (like JDO or JDBC), then I would say almost nothing.

    However if each of your service class do take configuration information, you can have multiple versions of those same classes, with different configuration information and different names. Also lets you consolidate different config file types. Spring applications tend to have two kind of config files: XML bean definition files and standard Java property files. And the config files for the web application would be similar (if not identical for the non-web components)

    Also if your service classes have other services as dependencies, its easier to unit test because you can use mock objects to represent the dependencies.

    If your services are DAO services, Spring offers a lot of functionality for specifying different DataSources during config time. Like JNDI datasources when deployed in the app server, and test datasources driven by config files during integration tests. You can declarative transactions and rollback logic without changing your acual objects using AOP proxies.

    Even for non-DAO services you also can add AOP proxies for things like common logging requirements without changing your code. Also it makes it very easy to put in debugging, performance testing and tracing code by just modifying your config files.

    This is what Spring is about. It is designed for you to create POJO business objects that don't care about things like transactions, object creation, creation of collaborators, wiring them together etc. Those things are applied in the configuration files. This allows for maximum flexibility. But if none of this flexibility is needed right now: I wouldn't bother. Spring is wonderful. But not for its own sake.

    Comment

    Working...
    X