[英]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.