Autowired无法使用球衣资源

Autowired无法使用球衣资源

本文介绍了@Autowired无法使用球衣资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

workflowService为空. Bean配置是正确的,因为手动注入在应用程序的其他部分工作正常.

workflowService is null. The bean configuration is correct because manual injection works fine in other portions of the application.

这是我的资源:

@Path("/workflowProcess")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public class WorkflowProcessResource {

    @Autowired
    WorkflowService workflowService;

    @Autowired
    WorkflowProcessService workflowProcessService;

    @GET
    @Path ("/getWorkflowProcesses/{uuid}")
    public Collection<WorkflowProcessEntity> getWorkflows (@PathParam("uuid") String uuid) {
        WorkflowEntity workflowEntity = workflowService.findByUUID(uuid);

        return workflowEntity.getWorkflowProcesses();
    }
}

根据我在Google上不断发现的内容,例如 http ://www.mkyong.com/webservices/jax-rs/jersey-spring-integration-example/,看起来ContextLoaderListener是关键.但是我已经将它添加到了应用程序上下文中.

From what I keep finding on Google on sites like http://www.mkyong.com/webservices/jax-rs/jersey-spring-integration-example/, it looks like ContextLoaderListener is the key. But I've already added that to the application context.

import com.sun.jersey.spi.container.servlet.ServletContainer;
import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
import org.atmosphere.cpr.AtmosphereFramework;
import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.handler.ReflectorServletProcessor;
import org.glassfish.grizzly.servlet.ServletRegistration;
import org.glassfish.grizzly.servlet.WebappContext;
import org.glassfish.grizzly.websockets.WebSocketAddOn;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.http.server.NetworkListener;

import java.io.IOException;
import java.util.logging.Logger;

public class Main {

    protected static final Logger logger = Logger.getLogger(Main.class.getName());

    public static void main(String[] args) throws IOException {
        logger.info("Starting server...");
        final HttpServer server = HttpServer.createSimpleServer(".", 8181);

        WebappContext ctx = new WebappContext("Socket", "/");

        //enable annotation configuration
        ctx.addContextInitParameter("contextClass", "org.springframework.web.context.support.AnnotationConfigWebApplicationContext");
        ctx.addContextInitParameter("contextConfigLocation", "com.production");

        //allow spring to do all of it's stuff
        ctx.addListener("org.springframework.web.context.ContextLoaderListener");

        //add jersey servlet support
        ServletRegistration jerseyServletRegistration = ctx.addServlet("JerseyServlet", new SpringServlet());
        jerseyServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "com.production.resource");
        jerseyServletRegistration.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.production.resource.ResponseCorsFilter");
        jerseyServletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
        jerseyServletRegistration.setLoadOnStartup(1);
        jerseyServletRegistration.addMapping("/api/*");

推荐答案

我认为您需要的是而不是@Autowired

What you need here, I think, is @InjectParam instead of @Autowired

这篇关于@Autowired无法使用球衣资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 20:11