Announcement Announcement Module
Collapse
No announcement yet.
Auto Creating Beans ??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Auto Creating Beans ???

    <bean id="authenticationService" class="com.xx.cp.authn.AuthenticationServiceImpl">
    <property name="userDao" ref="userDao"/>
    <property name="emailTemplateDao" ref="emailTemplateDao"/>
    </bean>

    <bean id="userDao" class="com.xx.cp.authn.UserDaoImpl">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

    <bean id="emailTemplateDao" class="com.xx.cp.authn.EmailTemplateDaoImpl">
    <property name="sessionFactory">
    <ref bean="sessionFactory1"/>
    </property>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="annotatedClasses">
    <list>
    <value>com.xx.cp.authn.User</value>
    </list>
    </property>
    <property name="hibernateProperties"> <value>hibernate.dialect=org.hibernate.dialect.HSQ LDialect</value>
    </property>
    </bean>

    <bean id="sessionFactory1" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource1"/>
    <property name="annotatedClasses">
    <list>
    <value>com.xx.cp.authn.EmailTemplate</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <value>hibernate.dialect=org.hibernate.dialect.HSQ LDialect</value>
    </property>
    </bean>



    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">

    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDrive r"/>
    <property name="url" value="jdbc:sqlserver://someIP:1059;database=IW"/>
    <property name="username" value="aa"/>
    <property name="password" value="aa"/>
    </bean>

    <bean id="dataSource1"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">

    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDrive r"/>
    <property name="url" value="jdbc:sqlserver://someIP:1445"/>

    <property name="username" value="bb"/>
    <property name="password" value="bb"/>
    </bean>

    </beans>



    I am getting

    java.lang.NullPointerException at org.springframework.orm.hibernate3.support.Hiberna teDaoSupport.getSession(HibernateDaoSupport.java:1 41)

    and I guess I know the problem.

    I am new to Springs and I guess I am also having same issue.

    What am I doing :

    BeanAAAImpl {

    fun() {
    new BeanBBBImpl(). bar() ;
    }

    }

    So actually from one bean, I am trying to create instance of other bean and getting same exception. Any idea how could I avaoid this exception. There is another thread http://forum.springframework.org/sho...t=32921&page=2 discussing the same issue but I can't understand how can I change my context.xml to create bean itself. Please help

  • #2
    Okay, I was able to resolve the issue.

    I use this and added emailtemplate definition in adminDao

    <bean id="adminDao" class="com.xx.cp.authn.AdminDaoImpl">
    <property name="emailTemplateDao" ref="emailTemplateDao"/>
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

    Comment


    • #3
      hehe, ok.

      By the way, if you use the Code-Tag (just press #), it makes source code looking much better...

      Comment


      • #4
        I don't understand how adding that configuration would get rid of the exception. If you are creating them using the new operator you are still going to have problems. BTW, I'm with you on the [code] [ /code] tags .
        Last edited by karldmoore; Aug 30th, 2007, 06:28 AM.

        Comment


        • #5
          Oh, I meant that first I get rid of that new operator and then used the above code to get the bean.

          It made me feel worst that I simply do not know basics on springs so I bought(actually free book, not bought) a book and read the whole chapter on bean creation. I now know how does it work :-).
          Last edited by monsee; Jun 14th, 2007, 09:19 AM.

          Comment


          • #6
            Originally posted by monsee View Post
            Oh, I meant that first I get rid of that new operator and then used the above code to get the bean. It made me feel worst that I simply do not know basics on springs so I bought a book and read the whole chapter on bean creation. I now know how does it work :-).
            Ok, that makes much more sense . Out of interest, which book did you go for?
            Last edited by karldmoore; Aug 30th, 2007, 06:28 AM.

            Comment


            • #7
              The tutorial given on Springs website v2.0.5. I found it very good

              Comment


              • #8
                Originally posted by monsee View Post
                The tutorial given on Springs website v2.0.5. I found it very good
                Ok I misunderstood, I thought you meant you'd got an actual book.
                Last edited by karldmoore; Aug 30th, 2007, 06:28 AM.

                Comment

                Working...
                X