You have an error in defining the RestController annotation. According to the docs this is:
public @interface RestController {
/ ** * The value may indicate a sentence for the logical component name, * to be converted to a Spring bean in case of component auto-detection. * @ return the suggested name of the component, if any * @since 4.0.1 * / String value () by default "";
}
This means that the value entered ("/ backoffice / tags") is the name of the controller, not the path that it is accessible to.
Add @RequestMapping("/backoffice/tags") to the controller class and remove the value from the @RestController annotation.
EDIT: A fully working example, according to the comment that it does not work - try using this code, please, and run locally from the IDE.
build.gradle
buildscript { ext { springBootVersion = '1.2.5.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'io.spring.dependency-management' jar { baseName = 'demo' version = '0.0.1-SNAPSHOT' } sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile("org.springframework.boot:spring-boot-starter-web") testCompile("org.springframework.boot:spring-boot-starter-test") } eclipse { classpath { containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER') containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8' } } task wrapper(type: Wrapper) { gradleVersion = '2.3' }
Tag.java
package demo; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class Tag { private final String tagName; @JsonCreator public Tag(@JsonProperty("tagName") String tagName) { this.tagName = tagName; } public String getTagName() { return tagName; } @Override public String toString() { final StringBuilder sb = new StringBuilder("Tag{"); sb.append("tagName='").append(tagName).append('\''); sb.append('}'); return sb.toString(); } }
SampleController.java
package demo; 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; import java.util.List; @RestController @RequestMapping("/backoffice/tags") public class SampleController { @RequestMapping(value = "/add", method = RequestMethod.POST) public void add(@RequestBody List<Tag> tags) { System.out.println(tags); } }
DemoApplication.java
package demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
source share