Frühjahr autowire funktioniert nicht null zurückgeben

Lerne ich spring jetzt. hier ist mein Beispielcode. ich bin mit jersey, spring, hibernate und mysql für meine REST-Dienst.

CustomerServiceImpl.java die REST-Endpunkt (Teil-code)

package com.samples.service.impl;

@Path("customers")
public class CustomerServiceImpl implements CustomerService {

    private static Logger logger = Logger.getLogger(CustomerServiceImpl.class);

    @Autowired
    CustomerBO customerBO;

hier ist CustomerBOImpl.java (Teil-code)

package com.samples.BO.impl;

@Component
public class CustomerBOImpl implements CustomerBO {

    @Autowired
    CustomerDAO customerDAO;

    @Autowired
    CustomerAdapter customerAdapter;

CustomerDAOImpl.class
package com.Proben.DAO.impl;

@Repository
public class CustomerDAOImpl implements CustomerDAO {

dies ist applicationContext.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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/context 
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://www.springframework.org/schema/tx 
              http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

<context:property-placeholder location="classpath*:database.properties"/>
<context:component-scan base-package="com.samples"/>
<context:annotation-config />

</beans>    

dies ist in der ersten paar Zeilen der Ausnahme bin ich immer.

http-bio-8090-exec-1] [class: CustomerServiceImpl] INFO  - list all customers
[http-bio-8090-exec-1] [class: CustomerServiceImpl] INFO  - customerBO is null
May 08, 2014 10:55:29 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
    at com.samples.service.impl.CustomerServiceImpl.getAllCustomers(CustomerServiceImpl.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvo

dies ist web.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
    <display-name>Employee Service</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>

        classpath*:applicationContext.xml
        </param-value>
    </context-param>

    <context-param>
        <param-name>initializeContextOnStartup</param-name> 
        <param-value>true</param-value> 
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener>

    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
            <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.samples.service</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>


</web-app>

also, wenn ich bin zu verstehen, wie dies funktioniert einwandfrei, ich bin configuring xml meine Komponenten autoscanned indem Sie das Paket unter, die ich ausführen möchten autoscan. und für Objekte, die ich will autowire. in CustomerServiceImpl Klasse, ich benutze @autowired für customerBO Objekt welches sollte wurden gescannt von @Component-annotation CustomerBOImpl.class definition. können Sie bitte helfen, warum mein auto-scan ist nicht Kommissionierung bis autowired customerBO Objekt?
danke.

ich bin mit der Feder und jersey. also ich glaube Trikot Aussehen sollte, für die @Weg, Ressourcen zu finden?
ja, bin ich. die vollständige Umsetzung verwendet maven, spring, jersey, hibernate, c3p0, mysql. aber es ist immer noch lite Gewicht übung für mich. dies ist mit einfachen REST-service.
Erinnere mich, dass Sie dies tun - finden Sie unter diesem answer
Wie sind Sie auf die Instanziierung der CustomerServiceImpl? Feder sollte eine exception werfen, wenn es nicht zu autowire eine Abhängigkeit...
chris, ich bin mit jersey, also bin ich mit der @Path-annotation für jersey zu Holen, die Ressource. ich sehe keine autowire Abhängigkeit von Fehlern in der log. es ist nur so, dass autowired bean ist tatsächlich null, das ist mein problem.

InformationsquelleAutor user3590506 | 2014-05-08

Schreibe einen Kommentar