Announcement Announcement Module
Collapse
No announcement yet.
Error creating bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error creating bean

    Error:
    53594 [http-88-Processor23] ERROR [/app].[action] - Servlet.service() for servlet action threw exception
    org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'com.lby.web.action.JobsListAction': Unsatisfied dependency expressed through bean property 'jobsDAO': There are 2 beans of type [com.lby.dao.JobsDAO] available for autowiring by type: [jobsDAO, example11Service]. There should have been exactly 1 to be able to autowire property 'jobsDAO' of bean 'com.lby.web.action.JobsListAction'. Consider using autowiring by name instead.
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireByType(Abstract AutowireCapableBeanFactory.java:909)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:807)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireBeanProperties( AbstractAutowireCapableBeanFactory.java:275)
    at org.springframework.web.struts.AutowiringRequestPr ocessor.processActionCreate(AutowiringRequestProce ssor.java:178)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:220)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:397)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:210)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:174)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:151)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:870)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:685)
    at java.lang.Thread.run(Thread.java:595)

    applicationApplication.xml:

    <?xml version="1.0" encoding="UTF-8"?>

    <!--
    - Application context definition for JPetStore's business layer.
    - Contains bean references to the transaction manager and to the DAOs in
    - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
    -->
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">
    <value>com.inet.tds.TdsDriver</value>
    </property>
    <property name="url">
    <value>jdbc:inetdae:127.0.0.1:1433?database=pubs </value>
    </property>
    <property name="username">
    <value>sa</value>
    </property>
    <property name="password">
    <value>sa</value>
    </property>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.SQLS erverDialect</prop>
    <prop key="connection.characterEncoding">GBK</prop>
    <prop key="hibernate.show_sql">true</prop>

    </props>
    </property>
    <property name="mappingDirectoryLocations">
    <list >
    <value>WEB-INF/classes/mapping</value>
    </list>
    </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>

    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.Hibernat eTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    <property name="allowCreate">
    <value>false</value>
    </property>
    </bean>
    <bean id="jobsDAO" class="com.lby.dao.impl.JobsDAOImpl" >
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
    </bean>
    <bean id="jobsListAction" class="com.lby.web.action.JobsListAction" >
    <property name="jobsDAO">
    <ref local="jobsDAO"/>
    </property>
    </bean>
    <bean id="exampleService"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean" >
    <property name="transactionManager">
    <ref local="transactionManager"/>
    </property>
    <property name="target">
    <ref local="jobsDAO"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="query">
    PROPAGATION_REQUIRED,readOnly
    </prop>
    <prop key="*">
    PROPAGATION_REQUIRED
    </prop>
    </props>
    </property>
    </bean>


    </beans>

    what's wrong ?

  • #2
    The problem is that you are using autowiring. I strongly recommend you don't use this!

    The second problem is that your exampleService is actually a proxy which wraps the jobDAO (target property is jobDAO), so the TPFB will create a proxy which implements the same interfaces as the target (jobDAO).

    I doubt that was your intention when you create the exampleService?

    Also, *please* wrap code fragments in code tags (using square brackets).

    Comment


    • #3
      Re:

      Originally posted by yatesco View Post
      The problem is that you are using autowiring. I strongly recommend you don't use this!

      The second problem is that your exampleService is actually a proxy which wraps the jobDAO (target property is jobDAO), so the TPFB will create a proxy which implements the same interfaces as the target (jobDAO).

      I doubt that was your intention when you create the exampleService?

      Also, *please* wrap code fragments in code tags (using square brackets).
      I'm a beginner of Spring, I don't know how to adjust it.
      Thanks.
      Last edited by linby; Aug 8th, 2007, 03:44 AM.

      Comment


      • #4
        Originally posted by linby View Post
        I'm a beginner of Spring, I don't know how to adjust it.
        Spring is throwing an Exception because you have selected Autowiring by type. You also have two bean definitions which both create an object that implements the same Interface (namely jobDAO and exampleService). That is the problem in a nutshell.

        The solution....

        It looks like you are defining an exampleService, however your bean definition for exampleService is simply wrapping the existing jobDAO in a Transactional proxy. I suspect you have a POJO called ExampleService which probably takes in a jobDAO right? The question (nothing to do with Spring) is which class should be exposed under the name "exampleService"? Is it jobListAction maybe? That looks like it would make sense.

        The second point is that you are using autowiring. The stack trace shows you are using Struts

        Code:
        org.springframework.web.struts.AutowiringRequestProcessor.processActionCreate(...)
        I don't see where you have defined that, so it is probably defined in another context. You don't have to use that implementation of the RequestProcessor. Take a look at http://static.springframework.org/sp...on.html#struts for more information.

        Comment


        • #5
          web.xml
          Code:
          <?xml version="1.0" encoding="Shift_JIS"?>
          
          <!DOCTYPE web-app
            PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
            "http://java.sun.com/dtd/web-app_2_3.dtd">
          
          <web-app>
          
          <context-param> 
          <param-name>contextConfigLocation</param-name> 
          <param-value>/WEB-INF/applicationContext.xml</param-value> 
          </context-param>
          
          <listener> 
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
          </listener> 
          
          
            <servlet>
              <servlet-name>action</servlet-name>
              <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
              <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/struts-config.xml</param-value>
              </init-param>
              <init-param>
                <param-name>debug</param-name>
                <param-value>2</param-value>
              </init-param>
              <init-param>
                <param-name>detail</param-name>
                <param-value>2</param-value>
              </init-param>
              <load-on-startup>2</load-on-startup>
            </servlet>
          
            <servlet-mapping>
              <servlet-name>action</servlet-name>
              <url-pattern>*.do</url-pattern>
            </servlet-mapping>
          
          </web-app>
          strut-config.xml
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
          <struts-config>
            <data-sources>
            </data-sources>
            <form-beans>
              <form-bean name="jobsForm" type="com.lby.web.form.JobsForm"/>
            </form-beans>
            <global-exceptions>
            </global-exceptions>
            <global-forwards>
            </global-forwards>
            <action-mappings>
              <action path="/main" name="jobsForm" type="com.lby.web.action.JobsListAction" scope="request">
                <forward name="list" path="/main.jsp"/>
                <forward name="edit" path="/editJobs.jsp"/>
                <forward name="create" path="/editJobs.jsp"/>
              </action>
            </action-mappings>
            <controller processorClass="org.springframework.web.struts.AutowiringRequestProcessor"/>
            <message-resources parameter="MessageResources"/>
          </struts-config>
          This right?
          Last edited by linby; Aug 8th, 2007, 04:16 AM.

          Comment


          • #6
            Yes, try using a different requestProcessor (defined in the last bean in strut-config.xml)

            To be honest, you really should read that documentation link I sent

            Comment

            Working...
            X