Results 1 to 8 of 8

Thread: Auto Creating Beans ???

  1. #1
    Join Date
    Jun 2007
    Posts
    8

    Post 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. #2
    Join Date
    Jun 2007
    Posts
    8

    Default

    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>

  3. #3
    Join Date
    Dec 2006
    Posts
    150

    Default

    hehe, ok.

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

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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 at 05:28 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  5. #5
    Join Date
    Jun 2007
    Posts
    8

    Default

    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 at 08:19 AM.

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote 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 at 05:28 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  7. #7
    Join Date
    Jun 2007
    Posts
    8

    Default

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

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote 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 at 05:28 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

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