samedi 18 avril 2015

Spring Boot 404 JSON Error

I am doing some basic spring boot sample. I'm trying to do some json POST.


i can't find resolve of this problem.


Accept: application/json


{ "question":"how old are you ?" } on http://localhost:7603/app but i get this errors



403 Forbidden Show explanation Loading time: 73
Request headers
Accept: application/json
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo

Content-Type: application/json
Accept-Encoding: gzip, deflate

Response headers
Server: Apache-Coyote/1.1
X-Application-Context: application:7603
Allow: HEAD, GET
Content-Length: 0
Date: Sat, 18 Apr 2015 23:38:24 GMT


__ Program Console Log___



Response does not contain any data.
2015-04-19 01:38:24.745 WARN 49144 --- [nio-7603-exec-3] o.s.web.servlet.PageNotFound : Request method 'POST' not supported





package org.apka;

import java.util.List;

import org.Entity.Question;
import org.Repository.DataRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app")
public class MainController {

protected final Log log = LogFactory.getLog(getClass());


private final DataRepository dataRepository;

@RequestMapping(method = RequestMethod.POST)
public void upload(@RequestBody Question question) {
dataRepository.save(question);
}

@Autowired
public MainController(DataRepository dataRepository) {

this.dataRepository = dataRepository;
}

@RequestMapping(method = RequestMethod.GET)
public List<Question> getAll() {

return (List<Question>) dataRepository.findAll();

}

}





package demo;

import java.util.Arrays;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
@ComponentScan("org.Repository.DataRepository")
public class DemoApplication {

public static void main(String[] args) {
ApplicationContext app = SpringApplication.run(DemoApplication.class,
args);

System.out.println("Witam:");

String[] beanNames = app.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}





package org.Entity;



import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
public class Question {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private String question;


protected Question() {}

public Question(String question) {
this.question = question;

}

@Override
public String toString() {
return String.format(
"Question[id=%d, question='%s']",
id, question);
}


}





package org.Repository;

import java.util.List;

import org.Entity.Question;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

@Repository
public interface DataRepository extends CrudRepository<Question, Long> {

List<Question> findByQuestion(String question);
}





?xml version="1.0" encoding="UTF-8"?>


http://ift.tt/VE5zRx"> 4.0.0



<groupId>org.test</groupId>
<artifactId>demo</artifactId>
<version>1.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>apka</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>org.apka.ApkaApplication</start-class>
<java.version>1.7</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://ift.tt/17sHSGD;
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://ift.tt/17sHSWR;
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://ift.tt/17sHSGD;
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://ift.tt/17sHSWR;
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

Aucun commentaire:

Enregistrer un commentaire