简体   繁体   English

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

[英]Adding dependency on another standalone Spring project?

I am creating two different but related applications. 我正在创建两个不同但相关的应用程序。 The first application is the backend for an iPhone/Android application, while the other one is a virtual store. 第一个应用程序是iPhone / Android应用程序的后端,而另一个应用程序是虚拟商店。 These two systems are not dependent on each other. 这两个系统不相互依赖。 So I could deploy only the virtual store or only the backend. 因此,我只能部署虚拟存储或仅部署后端。

Both of these application should authenticate against the same user database. 这两个应用程序都应针对相同的用户数据库进行身份验证。 So I have started on a third application for accessing this database which holds the user objects. 因此,我已经开始了用于访问该数据库的第三个应用程序,该数据库保存了用户对象。 The first thing that I thought was that this application could also stand on it own. 我认为的第一件事是该应用程序也可以独立存在。

The question is how I should use this shared user repository application in the other applications? 问题是我应该如何在其他应用程序中使用此共享用户存储库应用程序?

  • Should I create a dependency on the service-layer artifact and the domain-artifact and import the Spring config file in the other applications that I create? 是否应该在服务层工件和域工件上创建依赖项,并将Spring配置文件导入我创建的其他应用程序中?

  • Should I create a web service so I can make requests for user data in the other applications? 我是否应该创建一个Web服务,以便可以在其他应用程序中请求用户数据?

Or are there other options that are better? 还是还有其他更好的选择? Both the backend and virtual store are web service with REST principles applied. 后端商店和虚拟商店都是应用了REST原理的Web服务。 In the virtual store for instance I need to have access to user data from the common repository as well as adding store specific details. 例如,在虚拟商店中,我需要访问公共存储库中的用户数据,并需要添加商店特定的详细信息。

In my case I do like this (Project A is used in B.) :- 就我而言,我确实喜欢这样(项目A在B中使用):-

To use one project into another project I m using httpcomponents-client-4.2.2 library. 为了使用一个项目进入另一个项目,我使用httpcomponents-client-4.2.2库。

Step 1 : Copied jar of A in B. 第1步:将A中的A复制到B中。

Step 2 : In Project B :- 步骤2:在专案B中:-

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

Step 3 : In HTTPClientHelper class 步骤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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将另一个Spring MVC项目添加为依赖项后,Spring Boot无法找到适当的URL映射 - Spring boot can't find the appropriate URL mapping after adding another spring MVC project as a dependency Spring 引导项目 jar 作为另一个项目中的依赖项 - Spring Boot project jar as dependency in another project 如何在Spring MVC中将另一个项目添加为依赖项 - How to add another project as dependency in Spring MVC Spring Heroku 中的引导项目作为对另一个本地 Spring 引导项目的依赖项? - Spring boot project in Heroku as dependency to another local Spring Boot project? 将 spring boot maven 项目作为依赖添加到另一个项目(本地) - Add spring boot maven project as dependency to another project (locally) 在 spring 引导项目中添加 apache derby 的依赖项时出错 - Error adding the dependency for apache derby in spring boot project 添加 Spring 执行器依赖项后无法构建项目 - Unable to build project after adding Spring actuator dependency 添加 spring 启动验证依赖项后项目运行失败 - Project failed to run after adding spring boot validation dependency 向 spring 项目添加自定义依赖项后缺少类 - Missing classes after adding custom dependency to spring project Eclipse-如何将一个项目作为Maven依赖项添加到另一个项目中,而不是作为一个jar添加? - Eclipse - How to add a project as a Maven dependency to another, instead of adding as a jar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM