http status 404: Запрошенный ресурс недоступен. < /P>
< /blockquote> < br/> < /p>
Нет никаких признаков того, что в моем коде из консоли нет ошибки. Поэтому я не понимаю, почему я до сих пор не могу опубликовать данные. Я все перепроектировал.
контроллер
Код: Выделить всё
@Controller
public class CommerceController {
private static final Logger logger = LoggerFactory.getLogger(CommerceController.class);
private ProductService productService;
private UserService userService;
@Autowired
public void setProductService(ProductService productService) {
this.productService = productService;
}
/*//Map to store the product but later use database
MapprodData= new HashMap();*/
@RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json")
public
@ResponseBody
List home() {
System.out.println("This is the usermodel check it out: "+"Get REQUEST");
productService.runtest();
return productService.allProducts();
}
@RequestMapping("/products")
public List getProducts() {
productService.runtest();
return productService.allProducts();
}
//-------------------Create a User--------------------------------------------------------
@RequestMapping(value = "/user/", method = RequestMethod.POST, headers = "Content-Type:application/x-www-form-urlencoded")
public ResponseEntity createUser(@RequestBody UserModel user, UriComponentsBuilder ucBuilder) {
System.out.println("Creating User " + user.getName());
if (userService.isExist(user.getUsername())) {
System.out.println("A User with name " + user.getName() + " already exist");
return new ResponseEntity(HttpStatus.CONFLICT);
}
userService.createUser(user);
HttpHeaders headers = new HttpHeaders();
headers.setLocation(ucBuilder.path("/user/{id}").buildAndExpand(user.getId()).toUri());
return new ResponseEntity(headers, HttpStatus.CREATED);
}
/*public @ResponseBody Product home(){
logger.info("Starting getDammyProduct");
product.setName("SAMSUNG TV");
product.setId(1);
product.setCreatedDate(new Date());
return product;
}*/
}
enter code here
Код: Выделить всё
commerce
commerce
org.springframework.web.servlet.DispatcherServlet
1
commerce
/
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:com/javasoft/beans/config/dao-context.xml
classpath:com/javasoft/beans/config/security-context.xml
classpath:com/javasoft/beans/config/service-context.xml
Код: Выделить всё
& l t ; m o d e l V e r s i o n & g t ; 4 . 0 . 0 & l t ; / m o d e l V e r s i o n & g t ; < b r / > & l t ; g r o u p I d & g t ; c o m . j a v a s o f t . s m a r t s h o p p e r s & l t ; / g r o u p I d & g t ; < b r /> 0.0.1-SNAPSHOT
war
src
maven-war-plugin
2.6
WebContent
false
maven-compiler-plugin
3.3
1.8
1.8
Commerce
org.springframework
spring-core
4.2.6.RELEASE
org.springframework
spring-beans
4.2.6.RELEASE
org.springframework
spring-context
4.2.6.RELEASE
org.springframework
spring-web
4.2.6.RELEASE
org.springframework
spring-webmvc
4.2.6.RELEASE
com.fasterxml.jackson.core
jackson-databind
2.6.6
org.springframework.security
spring-security-core
4.1.3.RELEASE
org.springframework.data
spring-data-mongodb
1.9.4.RELEASE
org.mongodb
mongo-java-driver
3.3.0
javax.validation
validation-api
1.1.0.Final
org.springframework.security
spring-security-web
4.1.3.RELEASE
org.springframework.security
spring-security-config
4.1.3.RELEASE
org.springframework.security
spring-security-taglibs
4.1.3.RELEASE
org.springframework.webflow
spring-webflow
2.4.4.RELEASE
org.springframework
spring-context-support
4.3.3.RELEASE
@Document(collection = "users")
public class UserModel implements UserDetails, Serializable {
@Id
private String id;
private String name;
private String username;
private String password;
private String email;
/*Spring Security UserDetails*/
private List authorities;
private boolean accountNonExpired = true;
private boolean accountNonLocked = true;
private boolean credentialsNonExpired = true;
private boolean enable = false;
/*Empty constructor*/
public UserModel() {
}
/*Constructor with fields */
public UserModel(String name, String username, String password, String email, List authorities, boolean accountNonExpired, boolean accountNonLocked, boolean credentialsNonExpired, boolean enable) {
this.name = name;
this.username = username;
this.password = password;
this.email = email;
this.authorities = authorities;
this.accountNonExpired = accountNonExpired;
this.accountNonLocked = accountNonLocked;
this.credentialsNonExpired = credentialsNonExpired;
this.enable = enable;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Override
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public List getAuthorities() {
return authorities;
}
public void setAuthorities(List authorities) {
this.authorities = authorities;
}
@Override
public boolean isAccountNonExpired() {
return accountNonExpired;
}
public void setAccountNonExpired(boolean accountNonExpired) {
this.accountNonExpired = accountNonExpired;
}
@Override
public boolean isAccountNonLocked() {
return accountNonLocked;
}
public void setAccountNonLocked(boolean accountNonLocked) {
this.accountNonLocked = accountNonLocked;
}
@Override
public boolean isCredentialsNonExpired() {
return credentialsNonExpired;
}
public void setCredentialsNonExpired(boolean credentialsNonExpired) {
this.credentialsNonExpired = credentialsNonExpired;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
@Override
public boolean isEnabled() {
return enable;
}
}
< /code>
Запрос GET успешны, однако при публикации I получает ошибку 404. Я зарегистрировал метод поста, и я подтвердил, что его не вызывается. Может ли кто -нибудь любезно указать, где я могу сделать все неправильно или что -то пропустил?
Подробнее здесь: https://stackoverflow.com/questions/400 ... b-rest-api