2

我在 Eclipse 中使用 Spring 2.5 开发 Web 服务应用程序,在服务器上部署应用程序时出现以下错误:

    INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
4 juin 2012 17:06:06 org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MeteoPrevisionEndpoint' defined in class path resource [applicationContext-ws.xml]: Cannot resolve reference to bean 'MeteoServiceImpl' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'MeteoServiceImpl' is defined
    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.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:495)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:162)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'MeteoServiceImpl' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:971)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    ... 35 more
4 juin 2012 17:06:06 org.apache.catalina.core.StandardContext start
GRAVE: Error listenerStart
4 juin 2012 17:06:06 org.apache.catalina.core.StandardContext start
GRAVE: Erreur de démarrage du contexte [/Contenu20] suite aux erreurs précédentes
4 juin 2012 17:06:06 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
4 juin 2012 17:06:06 org.apache.coyote.http11.Http11Protocol start
INFO: Démarrage de Coyote HTTP/1.1 sur http-8080
4 juin 2012 17:06:07 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
4 juin 2012 17:06:07 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/188  config=null
4 juin 2012 17:06:07 org.apache.catalina.startup.Catalina start
INFO: Server startup in 10287 ms

我认为问题出在注释中,但我无法解决。这是代码:applicationContext-ws.xml

<?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:oxm="http://www.springframework.org/schema/oxm"

    xmlns:sws="http://www.springframework.org/schema/web-services"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

       http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-2.5.xsd
       http://www.springframework.org/schema/web-services
        http://www.springframework.org/schema/web-services/web-services-1.5.xsd">


<context:component-scan base-package="com.sample.services" /> 

    <!--
        ===================== SOAP =====================================
    -->

    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />


    <bean id="messageReceiver"

        class="org.springframework.ws.soap.server.SoapMessageDispatcher" />


<!--
        ===================== ENDPOINTS =====================================
    -->


    <bean id="MeteoPrevisionEndpoint" class="com.sample.ws.MeteoPrevisionEndpoint">

        <constructor-arg ref="MeteoServiceImpl" />

        <constructor-arg ref="marshaller" />
    </bean>


    <oxm:jaxb2-marshaller id="marshaller" contextPath="com.sample.schema" />    

    </beans>

MeteoService.java

public interface MeteoService {     
    List<Meteo> getMeteoPrevision(String date_jour,VilleClass ville);
}

MeteoServiceImpl.java

@Service("MeteoServiceImpl")
@Transactional
public class MeteoServiceImpl implements MeteoService {

    @Override
    @Transactional(readOnly = true)
    public List<Meteo> getMeteoPrevision(String date_jour,VilleClass ville) {
        List<Meteo> previsions = new ArrayList<Meteo>();
        Meteo meteoprevision=new Meteo();
        meteoprevision.setVille(ville); 
        meteoprevision.setTemp("20°");          
        previsions.add(meteoprevision);
        return previsions;
    }    

}

MeteoPrevisionEndpoint.java

@Endpoint
public class MeteoPrevisionEndpoint {   

    private static final Log logger = LogFactory.getLog(MeteoPrevisionEndpoint.class);
    private ObjectFactory objectFactory = new ObjectFactory();
    **private MeteoService meteoService;**
    private Marshaller marshaller;

    public MeteoPrevisionEndpoint(MeteoService meteoService, Marshaller marshaller) 
       {
        this.meteoService = meteoService;
        this.marshaller = marshaller; 
        }

    .....
}

如果我在 applicationContext-ws.xml 中使用服务“MeteoService”的显式定义,如下所示:

 <bean id="MeteoServiceImpl"
 class="com.sample.service.Impl.MeteoServiceImpl"> </bean>

我没有问题,但我想使用注释:((有人可以帮我吗?

4

1 回答 1

1

我发现了问题:D,包名称是“com.sample.service”而不是“com.sample.services”。非常感谢 JB Nizet :)

于 2012-06-05T09:47:56.093 回答