【问题标题】:JavaFX2: Consume Restful servicesJavaFX2:使用 Restful 服务
【发布时间】:2013-04-23 20:58:31
【问题描述】:

我正在尝试构建一种从 JavaFX 应用程序使用 RESTFul 服务的架构。要求是使用spring的rest模板(这个不要太紧。如果spring不起作用那么可能我可以看看jersey或resteasy。

我的设置如下:

我的主类有一个下拉列表,列出来自 RESTFul 服务的值。

打RESTFul服务的架构如下:

  1. 我有一个客户端类,它为我提供了访问其余服务的服务类实例。

  2. 在服务类中,我在 RESTFul 服务上使用了各种方法。

    public MyService1()
    {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            MyConfig.class);
        context.registerShutdownHook();
    }
    
    @Autowired
    private RestOperations restTemplate;
    
    private final Logger   LOG = LoggerFactory.getLogger(MyService1.class);
    
    public List<MyObject> getMyObjects() throws IOException
    {
        HttpEntity<MultiValueMap<String, HttpEntity<?>>> request = new HttpEntity<MultiValueMap<String, HttpEntity<?>>>(
            createParts(), createMultiPartHeaders());
    
        Map<String, String> vars = new HashMap<String, String>();
    
        List<MyObject> myObjects = restTemplate.getForObject(
            "http://localhost:8080/my-webservices/objects", List.class, vars);
    
        return myObjects;
    }
    

通过上述设置,我得到了异常:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)

【问题讨论】:

    标签: web-services spring rest javafx-2


    【解决方案1】:

    您似乎没有添加包含“BeanCreationException”类的依赖库。请添加 spring 的 jar 文件作为该 JavaFX 项目的依赖项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多