Results 1 to 2 of 2

Thread: Newbie question - understanding the value of Spring

  1. #1
    Join Date
    Jul 2005
    Posts
    1

    Default 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. #2
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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.

Similar Threads

  1. newbie jboss spring question
    By bsideindy in forum Data
    Replies: 2
    Last Post: Sep 9th, 2008, 01:15 PM
  2. Newbie Question - The Ideal Spring Solution
    By conorp in forum Architecture
    Replies: 3
    Last Post: Aug 23rd, 2005, 03:22 AM
  3. Newbie question: How to get spring debug logging on?
    By wangjammer5 in forum Container
    Replies: 2
    Last Post: Jul 15th, 2005, 07:11 AM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Spring newbie - http session question
    By ncubeait in forum Web
    Replies: 3
    Last Post: Sep 22nd, 2004, 11:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •