I am working with an example from https://spring.io/guides/gs/rest-service/ and I have changed the default class hello class to my class and when I call this in the web browser http: // localhost: 8080 / greeting I get a response:
There was an unexpected error (type=Not Acceptable, status=406).
Could not find acceptable representation
My controller:
package rest;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import database.*;
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
private DBAccess dbaccess= new DBAccess();
@RequestMapping("/greeting")
public Customer greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Customer(1,"a","b");
}
}
And client class:
package database;
public class Customer {
private long id;
private String firstName, lastName;
public Customer(){};
public Customer(long id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
void setFirstName(String firstName){
this.firstName=firstName;
}
void setLastName(String lastName){
this.lastName=lastName;
}
@Override
public String toString() {
return String.format(
"Customer[id=%d, firstName='%s', lastName='%s']",
id, firstName, lastName);
}
}
following the Spring MVC Rest / JSON service I added a portfolio pocket dependency, but it does not work ...
Please help me
According to the nebula comment. I do not have web.xml, I use the example from https://spring.io/guides/gs/rest-service/ and it is not.
Here is my Application.class
package rest;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
source
share