Results 1 to 4 of 4

Thread: BeanCreationException - How to configure applicationContext?

  1. #1
    Join Date
    Apr 2009
    Location
    Toronto, ON, Canada
    Posts
    3

    Default BeanCreationException - How to configure applicationContext?

    Hi to all members,
    I have a simple (but not for me) question
    I'm trying to set a connection pool for Jetty and Tomcat, in my Web Application, however I'm really confused hot to configure the spring applicationContext. I tried in many ways but with no succes
    This is part of my Spring appContext:
    Code:
     <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName">
    			<value>java:comp/env/jdbc/cs</value>
    		</property>
    		</bean>
    and the jetty-env.xml file:
    Code:
    <Configure class="org.mortbay.jetty.webapp.WebAppContext">
        <Set name="contextPath">/dev</Set>
        <New id="cs" class="org.mortbay.jetty.plus.naming.Resource">
             <Arg>jdbc/cs</Arg>
             <Arg>
                  <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"> 
                        <Set name="Url">jdbc:mysql://localhost/spring3</Set>
                        <Set name="DriverClassName">com.mysql.jdbc.Driver</Set>
                        <Set name="Username">root</Set>
                        <Set name="Password">root</Set>
                        <Set name="MaxActive">30</Set>
                        <Set name="MaxIdle">10</Set>
                        <Set name="MinIdle">2</Set>
                        <Set name="MaxWait">5000</Set>
                        <Set name="MinEvictableIdleTimeMillis">25000</Set>
                        <Set name="TimeBetweenEvictionRunsMillis">30000</Set>
                 </New>
             </Arg>
        </New>
    Finally in my web.xml I inserted :
    Code:
    <resource-ref>
           <res-ref-name>jdbc/cs</res-ref-name>
    	   <res-type>
    	         javax.sql.DataSource
    	   </res-type>
    	   <res-auth>Container</res-auth>
    	</resource-ref>
    Unfortunately I receive this error:
    Code:
    2009-06-11 14:35:57,687 [main] ERROR in [org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215)] - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GenericDAO' defined in class path resource [spring-bsi-core.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring-bsi-collab-war-applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring-bsi-collab-war-applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    And I don't know where is the problem!! I'm trying to avoid to put password and username in the applicationContext, even using a properties file, I would like to have all configuration files outside the WAR, so I can change DB or application server easier.
    Please help me I'm really stuck on this problems since days...
    Thanks in advance!

    Mystique

  2. #2
    Join Date
    Jul 2005
    Location
    Idaho
    Posts
    231

    Default

    Mystique,

    Can you post the relevant parts of your spring-bsi-core.xml?

    Steve O

  3. #3
    Join Date
    Apr 2009
    Location
    Toronto, ON, Canada
    Posts
    3

    Post core

    Hi Steve and thank you for you reply
    This is my spring-bsi-core.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
    	xmlns:aop="http://www.springframework.org/schema/aop" 
    	xmlns:context="http://www.springframework.org/schema/context" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	
    	xmlns:tx="http://www.springframework.org/schema/tx"	
    	
    	xsi:schemaLocation="
    	
    	http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans.xsd
    	
    	http://www.springframework.org/schema/context 
    	http://www.springframework.org/schema/context/spring-context-2.5.xsd 
    	
    	http://www.springframework.org/schema/aop  
    	http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 
    	
    	http://www.springframework.org/schema/tx  
    	http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
    	">
    
    	<bean id="GenericDAO" class="com.bsi.core.dao.AbstractHibernateGenericDAO">
          <property name="sessionFactory"><ref bean="sessionFactory"/></property>
        </bean>
        
    </beans>
    Thank you again! I hope you can help me

    Mystique

  4. #4
    Join Date
    Apr 2009
    Location
    Toronto, ON, Canada
    Posts
    3

    Post Jetty

    Actually I'm sure that the jetty-env.xml file is not loaded at all
    BTW I changed it again...but no results

    here is the xml jetty-env.xml :

    Code:
    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
    
    <!-- 
    We introduced this XML file to tell Jetty that our data 
    source is a MySQL database and also to tell Jetty how to connect to it. 
    To do this, we created this file jetty-env.xml in the WEB-INF directory 
    with contents along these lines:  
    -->
    
    <!--  This code:  <Arg>jdbc/cs</Arg> define the name of our DataSource -->
    
     <Configure class="org.mortbay.jetty.webapp.WebAppContext">
       
        <!--  This part belongs to a generic jetty.xml -->
        <Array id="plusConfig" type="java.lang.String">  
          <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>  
          <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>  
          <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>  
          <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>  
          <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
        </Array>
        
         <Call name="addLifeCycle">  
          <Arg>    
           <New class="org.mortbay.jetty.deployer.WebAppDeployer">      
            <Set name="contexts"><Ref id="Contexts"/></Set>      
            <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/collab</Set>      
            <Set name="parentLoaderPriority">false</Set>     
            <Set name="ConfigurationClasses"><Ref id="plusConfig"/></Set>    
            <Set name="extract">true</Set>         
            <Set name="allowDuplicates">false</Set>      
            <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>      
            <Set name="ConfigurationClasses"><Ref id="plusConfig"/></Set>    
           </New>  
         </Arg>
        </Call>
        
        
        
        <New id="cs" class="org.mortbay.jetty.plus.naming.Resource">
             <Arg>jdbc/cs</Arg>
             <Arg>
                  <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"> 
                        <Set name="Url">jdbc:mysql://localhost/spring3</Set>
                        <Set name="DriverClassName">com.mysql.jdbc.Driver</Set>
                        <Set name="Username">root</Set>
                        <Set name="Password">root</Set>
                        <Set name="MaxActive">30</Set>
                        <Set name="MaxIdle">10</Set>
                        <Set name="MinIdle">2</Set>
                        <Set name="MaxWait">5000</Set>
                        <Set name="MinEvictableIdleTimeMillis">25000</Set>
                        <Set name="TimeBetweenEvictionRunsMillis">30000</Set>
                 </New>
             </Arg>
        </New>
    
    </Configure>
    Any ideas?

    Thanks in advance !

Tags for this Thread

Posting Permissions

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