IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Problème d'autowiring [Framework]


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Décembre 2008
    Messages
    136
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 136
    Par défaut Problème d'autowiring
    Bonjour !

    J'essaye de mettre en place une petite application en utilisant Spring et Hibernate.
    Voilà mon soucis: quand je run le projet sur Tomcat, je me retrouve avec pleins d'erreurs concernant la création de beans et l'injection de dépendances.
    Voilà la trace d'erreurs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    GRAVE: Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.sebpx.subgeste.service.ContactService net.sebpx.subgeste.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    	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.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
    	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
    	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
    	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
    	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
    	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
    	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
    	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:680)
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.sebpx.subgeste.service.ContactService net.sebpx.subgeste.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    	... 30 more
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    	... 32 more
    14 mars 2012 11:53:29 org.apache.catalina.core.ApplicationContext log
    GRAVE: StandardWrapper.Throwable
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.sebpx.subgeste.service.ContactService net.sebpx.subgeste.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    	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.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
    	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
    	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
    	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
    	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
    	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
    	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
    	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:680)
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.sebpx.subgeste.service.ContactService net.sebpx.subgeste.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    	... 30 more
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    	... 32 more
    14 mars 2012 11:53:29 org.apache.catalina.core.StandardContext loadOnStartup
    GRAVE: La servlet /subgestetx a généré une exception "load()"
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    	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.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
    	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
    	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
    	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
    	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
    	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
    	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
    	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:680)
    Je ne vois vraiment pas d'ou vient cette première erreur : "No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency'. Cette classe existe !

    Voilà les différentes classes qui semblent poser problèmes :
    ContactService.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    package net.sebpx.subgeste.service;
     
     
    import java.util.List;
     
    import net.sebpx.subgeste.form.Contact;
     
    public interface ContactService {
     
        public void addContact(Contact contact);
        public List<Contact> listContact();
        public void removeContact(Integer id);
    }
    ContactServiceImpl.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    package net.sebpx.subgeste.service;
     
     
    import java.util.List;
     
    import net.sebpx.subgeste.dao.ContactDAO;
    import net.sebpx.subgeste.form.Contact;
     
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
     
     
    @Service
    public class ContactServiceImpl implements ContactService {
     
        @Autowired
        private ContactDAO contactDAO;
     
        @Transactional
        public void addContact(Contact contact) {
            contactDAO.addContact(contact);
        }
     
        @Transactional
        public List<Contact> listContact() {
     
            return contactDAO.listContact();
        }
     
        @Transactional
        public void removeContact(Integer id) {
            contactDAO.removeContact(id);
        }
    }
    ContactController.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    package net.sebpx.subgeste.controller;
     
    import java.util.Map;
     
     
    import net.sebpx.subgeste.form.Contact;
    import net.sebpx.subgeste.service.ContactService;
     
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
     
    @Controller
    public class ContactController {
     
    	@Autowired
    	private ContactService contactService;
     
    	@RequestMapping("/index")
    	public String listContacts(Map<String, Object> map) {
     
    		map.put("contact", new Contact());
    		map.put("contactList", contactService.listContact());
     
    		return "contact";
    	}
     
    	@RequestMapping(value = "/add", method = RequestMethod.POST)
    	public String addContact(@ModelAttribute("contact")
    	Contact contact, BindingResult result) {
     
    		contactService.addContact(contact);
     
    		return "redirect:/index";
    	}
     
    	@RequestMapping("/delete/{contactId}")
    	public String deleteContact(@PathVariable("contactId")
    	Integer contactId) {
     
    		contactService.removeContact(contactId);
     
    		return "redirect:/index";
    	}
    }
    spring-servlet.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    <?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"
        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">
     
     <context:annotation-config />
     <context:component-scan base-package="net.sebpx.subgeste.controller">
     </context:component-scan>
     
        <bean id="jspViewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass"
                value="org.springframework.web.servlet.view.JstlView" />
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
     
        <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="dataSource"
            class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
            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>
    </beans>
    web.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID" version="2.5">
        <display-name>Spring3-Hibernate</display-name>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
        <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>/</url-pattern>
        </servlet-mapping>
    </web-app>

    Si quelqu'un avait une piste, ça m'aiderait beaucoup !

    Merci d'avance

    Sebastian

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Novembre 2009
    Messages : 22
    Par défaut
    Je suis pas certain de ma réponse mais je dirais que

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    @Service
    public class ContactServiceImpl implements ContactService
    devrait peut-être être remplacé par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    @Service("ContactService")
    public class ContactServiceImpl implements ContactService
    ?

  3. #3
    Membre confirmé
    Inscrit en
    Décembre 2008
    Messages
    136
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 136
    Par défaut
    Merci pour ton aide miles_
    Malheureusement, j'ai le même problème avec "@Service("ContactService")"

  4. #4
    Membre éprouvé Avatar de chewing-gum
    Homme Profil pro
    Développeur Java
    Inscrit en
    Novembre 2009
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Novembre 2009
    Messages : 105
    Par défaut
    Je crois avoir repéré ton erreur. Le package que tu scannes est celui-ci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     <context:component-scan base-package="net.sebpx.subgeste.controller">
    MAIS tu dois aussi scanner les autres packages, pas seulement tes controller... Tu dois notamment scanner le package qui contient la classe ContactServiceImpl . Sinon, comment Spring pourrait-il utiliser les beans dont il n'a pas connaissance ?

    Bref, change simplement de package et écrit ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     <context:component-scan base-package="net.sebpx.subgeste">
    ça scannera tout ton projet.

    N'oublie pas d'ajouter l'annotation "@Service" sur la classe "ContactServiceImpl".

    Pour terminer, tu t'es trompé dans ton diagnostique :
    Je ne vois vraiment pas d'ou vient cette première erreur : "No matching bean of type [net.sebpx.subgeste.service.ContactService] found for dependency'. Cette classe existe !
    Cela ne signifie pas que ta classe n'existe pas dans ton projet, mais ça signifie plutôt que Spring ne contient pas de définition de beans du type ContactService.

  5. #5
    Membre confirmé
    Inscrit en
    Décembre 2008
    Messages
    136
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 136
    Par défaut
    Ahh c'était exactement ça !
    Merci beaucoup pour ton aide et tes explications chewing-gum !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Framework] Problème avec l'annotation Autowired
    Par riadhhwajdii dans le forum Spring
    Réponses: 5
    Dernier message: 17/02/2012, 20h39
  2. [MVC] Problème avec l'annotation @Autowired dans le @Controller
    Par rolandl dans le forum Spring Web
    Réponses: 0
    Dernier message: 31/12/2011, 02h18
  3. [Framework] Problème "Error creating Bean : Autowiring of fields failed"
    Par fedora8 dans le forum Spring
    Réponses: 1
    Dernier message: 17/05/2011, 17h22
  4. Spring probléme Autowiring
    Par kamalkane dans le forum Spring Web
    Réponses: 1
    Dernier message: 07/12/2010, 15h44
  5. [Data] JavaConfig et Autowiring : problème de bean unique
    Par Invité dans le forum Spring
    Réponses: 1
    Dernier message: 22/06/2009, 12h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo