Announcement Announcement Module
Collapse
No announcement yet.
Instantiating JdbcDaoSupport in non spring java application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Instantiating JdbcDaoSupport in non spring java application

    Hello,

    We have a non spring application which uses some support jars (the code in the jars are spring beans). For e.g., we have a Custom DAO that extends JdbcDaoSupport and uses DataFieldMaxValueIncrementer. We need to use this custom DAO in a non spring application (which is not spring context aware). We thought we could manually instantiate Custom DAO class in the client code, but we are stuck with how to instantiate the DataFieldMaxValueIncrementer. Are there any best practices on how to instantiate spring beans in a non spring application (that is not spring context aware). Help is appreciated.

  • #2
    Spring classes, by and large, are just plain POJOs that can be created and used anywhere, whether inside the framework or out. Just pick the constructor you want, set any other optional properties as appropriate, and make sure to initialize the object if necessary. Make sure to account for any teardown that needs to happen when you're done with it, too. If you can point to some specific problem you're having, someone might be able to give you more specific guidance.

    Comment


    • #3
      So if we have to instantiate our custom class that extends springs "JndiObjectFactoryBean" class and this JndiObjectFactoryBean class has a dependency on org.springframework.beans.factory.config.Propertie sFactoryBean. So we have to instantiate PropertiesFactoryBean first and then set this on our custom class (which extends JndiObjectFactoryBean ). Is this the right approach?

      Comment


      • #4
        That sounds correct, but I'm not sure why you'd want to use a JndiObjectFactoryBean outside of a Spring context. If you need to get something from JNDI, just create and use a JndiTemplate.

        Comment


        • #5
          Well, I am trying to use existing jars (that have spring beans) in my non spring application. So for e.g. the Jar file has a custom DAO (with a property of AbstractDataFieldMaxValueIncrementer and another property of datasource which is a JndiObjectFactoryBean ) and since unfortunately I can't make my application spring context aware, I have to go through this chain of creating the beans manually in my code.

          Comment


          • #6
            Also, using a PropertiesFactoryBean is just a long way of saying PropertiesLoaderUtils.loadProperties(somewhere)

            Comment


            • #7
              Originally posted by saketh View Post
              Well, I am trying to use existing jars (that have spring beans) in my non spring application. So for e.g. the Jar file has a custom DAO (with a property of AbstractDataFieldMaxValueIncrementer and another property of datasource which is a JndiObjectFactoryBean )
              I'm afraid, then, that it sounds like whoever created that jar has made your life rather difficult by not understanding how Spring works. So yes, it sounds like you'll be stuck creating the factory beans and making sure their appropriate lifecycle methods are called. As for the max value incrementer, you should just be able to pick any implementation of the DataFieldMaxValueIncrementer interface.

              Comment


              • #8
                Originally posted by saketh View Post
                and another property of datasource which is a JndiObjectFactoryBean
                Wait, do you mean the property is of type DataSource or of type JndiObjectFactoryBean? It should absolutely be the former. It makes no sense for it to be the latter.

                Comment

                Working...
                X