web-dev-qa-db-ja.com

org.springframework.beans.factory.NoSuchBeanDefinitionException:「customerService」という名前のBeanは定義されていません

WebアプリケーションをTomcatにデプロイしようとすると、このエラーを修正するのに助けが必要です。 customerService Beanが定義されていないのはなぜですか? web.xmlに何か欠けているのですか、それとも何とかcustomerServiceをマップする必要がありますか?マッピングに注釈を使用しています。どんな助けも大歓迎です。 localhostログからのエラーログエントリは次のとおりです。

エラー:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'customerService' is defined
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.Java:306)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1106)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.Java:384)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.Java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.Java:111)
    at org.Apache.catalina.core.StandardContext.listenerStart(StandardContext.Java:4600)
    at org.Apache.catalina.core.StandardContext$1.call(StandardContext.Java:5097)
    at org.Apache.catalina.core.StandardContext$1.call(StandardContext.Java:5092)
    at Java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.Java:334)
    at Java.util.concurrent.FutureTask.run(FutureTask.Java:166)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1110)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:603)
    at Java.lang.Thread.run(Thread.Java:722)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'customerService' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.Java:529)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.Java:1095)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:277)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:197)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.Java:442)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.Java:416)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.Java:549)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.Java:150)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:87)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.Java:303)
    ... 21 more

Apr 30, 2012 11:17:09 AM org.Apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Apr 30, 2012 11:23:19 AM org.Apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextDestroyed()
Apr 30, 2012 11:23:19 AM org.Apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextDestroyed()
Apr 30, 2012 11:23:20 AM org.Apache.catalina.core.ApplicationContext log
INFO: Destroying Spring FrameworkServlet 'spring'
Apr 30, 2012 11:23:20 AM org.Apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Apr 30, 2012 11:23:27 AM org.Apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Apr 30, 2012 11:23:33 AM org.Apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
Apr 30, 2012 11:23:35 AM org.Apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Apr 30, 2012 11:23:35 AM org.Apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Apr 30, 2012 11:23:57 AM org.Apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Apr 30, 2012 11:23:58 AM org.Apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'customerService' is defined
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.Java:306)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1106)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.Java:384)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.Java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.Java:111)
    at org.Apache.catalina.core.StandardContext.listenerStart(StandardContext.Java:4600)
    at org.Apache.catalina.core.StandardContext$1.call(StandardContext.Java:5097)
    at org.Apache.catalina.core.StandardContext$1.call(StandardContext.Java:5092)
    at Java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.Java:334)
    at Java.util.concurrent.FutureTask.run(FutureTask.Java:166)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1110)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:603)
    at Java.lang.Thread.run(Thread.Java:722)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'customerService' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.Java:529)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.Java:1095)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:277)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:197)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.Java:442)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.Java:416)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.Java:549)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.Java:150)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:87)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.Java:303)
    ... 21 more

web.xml (mistest/WebContent/WEB-INF) *Updated*

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 
         xmlns="http://Java.Sun.com/xml/ns/j2ee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://Java.Sun.com/xml/ns/j2ee 
         http://Java.Sun.com/xml/ns/j2ee/web-app_2_4.xsd">

   <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

    <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/mistest/*</url-pattern>
    </servlet-mapping>

    <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>



 </web-app>

顧客サービス

package testapp.mis.service;

import Java.util.List;

import testapp.mis.domain.Customer;

public interface CustomerService {


    public List<Customer> retrieveAllCustomerNames();
    public List<Customer> retrieveAllCustomerCountries();
    public void createCustomer(Customer customer);
    public List<Customer> retrieveAllCustomers();

}

ヘルプのおかげで、他のファイルを作成する必要があるかどうかを教えてください。

編集: applicationContext.xmlおよびcustomerService実装ファイルは次のとおりです。

applicationContext.xml (mistest/WebContent/WEB-INF) *Updated*

<?xml  version="1.0" encoding="UTF-8"?>
<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:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
         http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:annotation-config/>
    <context:component-scan base-package="testapp.mis"/>
    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
            p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="0"/>

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages"/>
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>
</beans>

customerServiceImpl:

package testapp.mis.service;

import Java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import testapp.mis.dao.CustomerDao;
import testapp.mis.domain.Customer;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired(required=true)
    private CustomerDao customerDao;

    @Transactional
    public List<Customer> retrieveAllCustomerNames() {
        return this.customerDao.getAllCustomerNames();
    }

    @Transactional
    public List<Customer> retrieveAllCustomerCountries() {
        return this.customerDao.getAllCustomerCountries();
    }

    @Transactional
    public void createCustomer(Customer customer){
        this.customerDao.saveCustomer(customer);
    }

    @Transactional
    public List<Customer> retrieveAllCustomers(){
        return this.customerDao.getAllCustomers();
    }

}

Edit2:

これがCustomerControllerです。提案どおり@Autowiredを追加しました。

package testapp.mis.controller;

//import javax.annotation.Resource;
import Java.util.List;

import testapp.mis.service.CustomerService;
import testapp.mis.domain.Customer;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.beans.factory.annotation.Autowired;


@Controller
@RequestMapping("/customer")
public class CustomerController {



    /*@Resource(name="customerService")
    private CustomerService customerService;
    */
    @Autowired
    private CustomerService customerService;


    @RequestMapping(value="/list", method=RequestMethod.GET)
    public String getCustomerList(Model model) {
        List<Customer> customers = customerService.retrieveAllCustomers();
        System.out.println("test");
        model.addAttribute("customerList", customers);

        return "customer";
    }

    @RequestMapping(value="/add", method=RequestMethod.GET)
    public String getCustomer(Model model) {

        model.addAttribute("customerAttribute", new Customer());

        return "new-customer";
    }

    @RequestMapping(value="/add", method=RequestMethod.POST)
    public String postCustomer(@ModelAttribute("customerAttribute") Customer customer) {
        customerService.createCustomer(customer);

        return "redirect:/mis/customer/list";
    }
} 

spring-servlet.xml(mistest/WebContent/WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- Declare a view resolver -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
            p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

</beans>

hibernate-context.xml(mistest/WebContent/WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
      ">

 <context:property-placeholder location="/WEB-INF/spring.properties" />

    <!-- Enables annotations for transaction management -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- Declare the Hibernate SessionFactory for retrieving Hibernate sessions -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
        p:dataSource-ref="dataSource"
        p:configLocation="${hibernate.config}"
        p:packagesToScan="testapp.mis"/>

 <!-- Declare a datasource that has pooling capabilities--> 
 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close"
    p:driverClass="${app.jdbc.driverClassName}"
    p:jdbcUrl="${app.jdbc.url}"
    p:user="${app.jdbc.username}"
    p:password="${app.jdbc.password}"
    p:acquireIncrement="5"
    p:idleConnectionTestPeriod="60"
    p:maxPoolSize="100"
    p:maxStatements="50"
    p:minPoolSize="10" />

 <!-- Declare a transaction manager-->
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
          p:sessionFactory-ref="sessionFactory" />

</beans>

hibernate.cfg.xml(mistest/WebContent/WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>

   <!-- We're using MySQL database so the dialect needs to MySQL as well-->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    <!-- Enable this to see the SQL statements in the logs-->
    <property name="show_sql">false</property>

    <!-- Remove after testing -->

    <!-- This will drop our existing database and re-create a new one.
      Existing data will be deleted! -->
    <property name="hbm2ddl.auto">create</property>
  </session-factory>
</hibernate-configuration>

/ D

13
dlinx90

例外を読むことにより、customerServiceの自動配線を忘れたことが確実です

カスタマーサービスを自動接続する必要があります。

コントローラクラスに以下の変更を加えます

@Controller
public class CustomerController{

    @Autowired
    private Customerservice customerservice;
......other code......

}

再びあなたのサービス実装クラス

書きます

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDAO customerDAO;
......other code......

.....add transactional methods
}

Hibernateを使用している場合、applicationcontext xmlファイルに必要な変更を加えます(セッションファクトリの構成が必要です)。

dAO実装でsessionFactory setメソッドを自動配線する必要があります

サンプルアプリケーションのコンテキストを見つけてください:

<?xml  version="1.0" encoding="UTF-8"?>
<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:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.sparkle" />
    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
            p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="0" />

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <!-- <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties" /> -->

     <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">         
        <list>
            <value>/WEB-INF/jdbc.properties</value>          

        </list>    
    </property>     
    </bean>




    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
        p:password="${jdbc.password}" />


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>

    <tx:annotation-driven />


   <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
          p:sessionFactory-ref="sessionFactory"/>


</beans>

私はjdbcのURLとドライバの仕様にjdbc.propertiesファイルを使用していることに注意してください

9
JOHND

@Serviceと言ったので、サービスにI am using annotations for mappingの注釈を付ける必要があります

4
mprabhat

Web.xmlファイルで指定することにより、applicationContext.xmlファイルがロードされていることを確認してください。

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
3
ndeverge

ちょうど別の可能性:Springは、名前でBeanを定義しない場合、名前ではなくタイプでBeanを初期化します。

プロデューサー:

_@Service
public void FooServiceImpl implements FooService{}
_

消費者:

_@Autowired
private FooService fooService;
_

または

_@Autowired
private void setFooService(FooService fooService) {}
_

ただし、名前で使用する場合は問題ありません。

_ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
ctx.getBean("fooService");
_

文句を言う:_org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'fooService' is defined_この場合、@Service("fooService")に名前を割り当てると機能します。

2
Tiina