添加依赖于另一个独立的Spring项目?

时间:2014-07-08 08:11:13

标签: java spring maven java-ee

我正在创建两个不同但相关的应用程序。第一个应用程序是iPhone / Android应用程序的后端,而另一个是虚拟商店。这两个系统并不相互依赖。所以我只能部署虚拟商店或只部署后端。

这两个应用程序都应针对同一个用户数据库进行身份验证。所以我开始使用第三个访问该数据库的应用程序来保存用户对象。 我认为第一件事就是这个应用程序也可以独立存在。

问题是如何在其他应用程序中使用此共享用户存储库应用程序?

  • 我应该在服务层工件和域工件上创建依赖关系,并在我创建的其他应用程序中导入Spring配置文件吗?

  • 我应该创建一个Web服务,以便在其他应用程序中提出用户数据请求吗?

还是有更好的其他选择吗?后端和虚拟存储都是应用了REST原则的Web服务。例如,在虚拟商店中,我需要访问公共存储库中的用户数据以及添加商店特定的详细信息。

1 个答案:

答案 0 :(得分:0)

在我的情况下,我喜欢这样(项目A在B中使用): -

要将一个项目用于另一个项目,我使用 httpcomponents-client-4.2.2 库。

第1步:在B中复制了一罐A。

第2步:在项目B中: -

HTTPClientHelper httpClientHelper = new HTTPClientHelper();
HttpEntity httpEntity = httpClientHelper.GET(uri + param);
InputStream inputStream = httpEntity.getContent();
//    ... do other stuffs

第3步:在HTTPClientHelper类

// Constructor
public HTTPClientHelper() {
    httpclient = new DefaultHttpClient();
    localContext = new BasicHttpContext();
}

// Execute HTTP GET method of given Service URL
public HttpEntity GET(String url) {
    HttpGet get = new HttpGet(url);

    try {
        response = httpclient.execute(get, localContext);
        httpEntity = response.getEntity();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return httpEntity;
}

// Execute HTTP POST method of given Service URL
public HttpEntity POST(String url, boolean sendData) {

    HttpPost post = new HttpPost(url);
    if (sendData) {
        post.setEntity(getUrlEncodedFormEntity());
    }
    try {
        response = httpclient.execute(post, localContext);
        httpEntity = response.getEntity();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return httpEntity;
}

// Create a list of <name, value> for user name & password
public void createHttpEntity(String name, String value) {
    try {
        nameValuePairs.add(new BasicNameValuePair(name, value));
        setUrlEncodedFormEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

public UrlEncodedFormEntity getUrlEncodedFormEntity() {
    return urlEncodedFormEntity;
}

public void setUrlEncodedFormEntity(UrlEncodedFormEntity urlEncodedFormEntity) {
    this.urlEncodedFormEntity = urlEncodedFormEntity;
}
相关问题