Java Spring@Autowired在@Endpoint中不工作

Java Spring@Autowired在@Endpoint中不工作,java,spring,web-services,Java,Spring,Web Services,我想通过Spring框架创建一些Web服务,但我发现有些错误,@Autowired在@Endpoint中不起作用。请查看我的代码: @Endpoint public class VideoEndpoint { private VideoService videoService; @Autowired public VideoEndpoint(VideoService videoService) {

我想通过Spring框架创建一些Web服务,但我发现有些错误,
@Autowired
@Endpoint
中不起作用。请查看我的代码:

    @Endpoint
    public class VideoEndpoint
    {
        private VideoService videoService;
        @Autowired
        public VideoEndpoint(VideoService videoService)
        {
            this.videoService=videoService;
        }

        @PayloadRoot(namespace = "http://www.skysoft.top/ws/video", localPart = "GetVideoRequest")
        @ResponsePayload
        public GetVideoResponse findVideoById(@RequestPayload GetVideoRequest request)
                throws Exception
        {
            GetVideoResponse response = new GetVideoResponse();
            Video video=videoService.getVideoByAid(request.getAid());
            response.setVideo(video);
            return response;
        }
    }


    public interface VideoService {

        List<Video> getVideoList();
        Video getVideoByAid(long aid);
    }


    @Service("videoService")
    @Transactional
    public class VideoServiceImpl implements VideoService {
        private final Logger LOG = LoggerFactory.getLogger(this.getClass());
        @Autowired
        private VideoDao videoDao;
        @Autowired
        private RedisCache cache;


        @Override
        public List<Video> getVideoList() {
            String cache_key=RedisCache.CAHCENAME+"|getVideoList";
            //先去缓存中取
            List<Video> result_cache=cache.getListCache(cache_key, Video.class);
            if(result_cache==null){
                //缓存中没有再去数据库取,并插入缓存(缓存时间为60秒)
                result_cache=videoDao.queryAll();
                cache.putListCacheWithExpireTime(cache_key, result_cache, RedisCache.CAHCETIME);
                LOG.info("put cache with key:"+cache_key);
            }else{
                LOG.info("get cache with key:"+cache_key);
            }
            return result_cache;
        }
    @Override
        public Video getVideoByAid(long aid) {
            return videoDao.queryByAid(aid);
        }


    }
    This is my Spring-ws-servelet.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: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-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/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
        <context:annotation-config/>
        <!-- 自动扫描@Endpoint注解 -->
        <!--<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter" />-->
        <!--<context:component-scan base-package="com.yingjun.ssm.service" />-->
        <context:component-scan base-package="com.yingjun.ssm.ws.endpoint" />
        <!-- 开启Spring WebService的注解自动扫描驱动 -->
        <sws:annotation-driven/>
        <!-- 动态WSDL的配置 -->
        <sws:dynamic-wsdl id="video" portTypeName="VideoOperation" locationUri="/webservice/video"
                          targetNamespace="http://www.skysoft.top/ws/video">
            <sws:xsd location="classpath:wsdl/video.xsd" />
        </sws:dynamic-wsdl>


    </beans>

This is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1">

    <!--配置DispatcherServlet -->
    <servlet>
        <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 配置SpringMVC需要加载的配置文件 spring-xxx.xml -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/spring-*.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-dispatcher</servlet-name>
        <!--默认匹配所有的请求 -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- druid -->
    <servlet>
        <servlet-name>DruidStatView</servlet-name>
        <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>DruidStatView</servlet-name>
        <url-pattern>/druid/*</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>DruidWebStatFilter</filter-name>
        <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
        <init-param>
            <param-name>exclusions</param-name>
            <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>DruidWebStatFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/spring-ws-servlet.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/webservice/*</url-pattern>
    </servlet-mapping>
</web-app>

 This is my spring-service.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: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-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/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
    <context:annotation-config/>
    <!-- 自动扫描@Endpoint注解 -->
    <!--<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter" />-->
    <!--<context:component-scan base-package="com.yingjun.ssm.service" />-->
    <context:component-scan base-package="com.yingjun.ssm.ws.endpoint" />
    <!-- 开启Spring WebService的注解自动扫描驱动 -->
    <sws:annotation-driven/>
    <!-- 动态WSDL的配置 -->
    <sws:dynamic-wsdl id="video" portTypeName="VideoOperation" locationUri="/webservice/video"
                      targetNamespace="http://www.skysoft.top/ws/video">
        <sws:xsd location="classpath:wsdl/video.xsd" />
    </sws:dynamic-wsdl>


</beans>

我发现了很多解决方案,但都不起作用。

我不是专家,但我认为您的end point类不知道您的applicationContext。将其放在
web.xml的顶部

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-*.xml</param-value>
</context-param>

org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/spring-*.xml
您定义的每个*-servlet.xml文件都有不同的上下文,“contextLoaderListener”将创建一个父上下文,以便您可以在上下文之间共享bean

如果这不起作用,请尝试将其添加到
标记内的Spring-ws-servelet.xml中

<import resource="spring-service.xml"/>

我不是专家,但我认为您的end point类不知道您的applicationContext。将其放在
web.xml的顶部

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-*.xml</param-value>
</context-param>

org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/spring-*.xml
您定义的每个*-servlet.xml文件都有不同的上下文,“contextLoaderListener”将创建一个父上下文,以便您可以在上下文之间共享bean

如果这不起作用,请尝试将其添加到
标记内的Spring-ws-servelet.xml中

<import resource="spring-service.xml"/>



我假设所有这些类都有“com.yingjun.ssm.ws.endpoint”包?似乎VideoServiceImpl类尚未注册?谢谢。我的项目中有许多配置文件,例如spring-service.xml,该文件将注册服务类videoserviceinpl。但是@Endpoint似乎找不到spring-service.xml注册的类,这很奇怪。post your web.xml不是它抱怨的端点。找不到com.yingjun.ssm.service.VideoService接口。也许还可以对这个界面进行注释。@David Florez,谢谢。我已经发布了web.xml。我假设所有这些类都有“com.yingjun.ssm.ws.endpoint”包?似乎VideoServiceImpl类尚未注册?谢谢。我的项目中有许多配置文件,例如spring-service.xml,该文件将注册服务类videoserviceinpl。但是@Endpoint似乎找不到spring-service.xml注册的类,这很奇怪。post your web.xml不是它抱怨的端点。找不到com.yingjun.ssm.service.VideoService接口。也许还可以对这个界面进行注释。@David Florez,谢谢。我已经发布了web.xml。这是通过xml连接的,@annotion将其用作替代方案。如果你看一下stacktrace,它说
没有[com.yingjun.ssm.service.VideoService]类型的合格bean
。Autowired正在寻找类型匹配。我强烈认为@annocation接口会起作用。@David Florez谢谢。但是在我的项目spring-service.xml中没有applicationContext.xml@孙盼盼 我用新的答案修改了我的答案info@David弗洛雷斯,太完美了!它解决了我的问题!非常感谢你@大卫·弗洛雷斯完成了。谢谢。这是通过XML连接的,@annotion将其用作替代方案。如果你看一下stacktrace,它说
没有[com.yingjun.ssm.service.VideoService]类型的合格bean
。Autowired正在寻找类型匹配。我强烈认为@annocation接口会起作用。@David Florez谢谢。但是在我的项目spring-service.xml中没有applicationContext.xml@孙盼盼 我用新的答案修改了我的答案info@David弗洛雷斯,太完美了!它解决了我的问题!非常感谢你@大卫·弗洛雷斯完成了。非常感谢。