ConsumerData
package org.apache.fineract.lab.data;
import java.util.Date;
public class ConsumerData {
private String uniqueIndentifier;
private String firstName;
private String lastName;
private Boolean active;
private Date lastModified;
public ConsumerData(){
super();
}
public String getUniqueIndentifier() {
return uniqueIndentifier;
}
public void setUniqueIndentifier(String uniqueIndentifier) {
this.uniqueIndentifier = uniqueIndentifier;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
}
ConsumersApiResource
package org.apache.fineract.lab.api;
import org.apache.fineract.lab.data.ConsumerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Collection;
import java.util.HashMap;
@Path("/consumers")
@Component
@Scope("singleton")
public class ConsumersApiResource {
private static final Logger LOGGER= LoggerFactory.getLogger(ConsumersApiResource.class);
private final HashMap<String,ConsumerData>mockedConsumerData=new HashMap<>();
public ConsumersApiResource() {
super();
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Collection<ConsumerData> fetchAll()
{
return this.mockedConsumerData.values();
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response createConsumer (final ConsumerData consumerData)
{
this.mockedConsumerData.put(consumerData.getUniqueIndentifier(),consumerData);
return Response.status(Response.Status.CREATED).build();
}
}
extensionContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:sec="http://www.springframework.org/schema/security"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<context:annotation-config/>
<context:component-scan base-package="org.apache.fineract.lab"/>
<jpa:repositories base-package="org.apache.fineract.lab.api"/>
</beans>
错误:
当我尝试POST并从 / consumers 路径获取数据时,我得到以下未找到错误。没有得到Endpoint但我无法解决此问题。
{
"timestamp": 1466503124489,
"status": 404,
"error": "Not Found",
"message": "Not Found",
"path": "/fineract-provider/api/v1/consumers"
}
请帮我解决这个问题。谢谢。
答案 0 :(得分:0)
您需要导入extensionContext.xml。
在appContext.xml中添加<import resource="extensionContext.xml"/>
行。