小编use*_*820的帖子

Web服务中的Spring自动连接无法正常工作

我必须遗漏一些简单的东西,但是我无法将一个Autowired属性分配给bean.这里发布的所有类似答案似乎围绕三种解决方案中的一种:

  1. 扩展SpringBeanAutowiringSupport
  2. 在applicationContext.xml中使用<context:component-scan base-package ="..."/>
  3. 在applicationContext.xml中使用<context:annotation-config />

我尝试制作一个简约bean来代表我的DAO并将其注入Web服务.

DAO界面:

package wb;
public interface FooDAO {
    public String doNothing();
}
Run Code Online (Sandbox Code Playgroud)

DAO实施:

package wb;
import org.springframework.stereotype.Component;

@Component
public class FooDAOImpl implements FooDAO {
    public FooDAOImpl() {
        System.out.println("FooDAOImpl: Instantiated " + this);
    }

    @Override
    public String doNothing() {
        System.out.println("FooDAOImpl: doNothing() called");
        return "Did nothing!";
    }
}
Run Code Online (Sandbox Code Playgroud)

注入Web服务:

package ws;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import wb.FooDAO;

@WebService(serviceName = "WS")
public class WS extends SpringBeanAutowiringSupport {

    @Autowired(required = true) …
Run Code Online (Sandbox Code Playgroud)

java spring autowired java-ee

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

autowired ×1

java ×1

java-ee ×1

spring ×1