spring boot - HATEOAS methods not found -
my controller can't seem find hateoas methods "linkto".
am missing something?
pom.xml
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>org.springframework</groupid> <artifactid>provider</artifactid> <version>0.1.0</version> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.1.5.release</version> </parent> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <!-- spring security --> <!-- auto configured, remove dependencies disable. --> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-web</artifactid> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-config</artifactid> </dependency> <!-- oauth 2.0 --> <dependency> <groupid>org.springframework.security.oauth</groupid> <artifactid>spring-security-oauth2</artifactid> <version>2.0.1.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-test</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-test-mvc</artifactid> <version>1.0.0.m2</version> <scope>test</scope> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-databind</artifactid> </dependency> <!-- spring mongodb --> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-mongodb</artifactid> </dependency> <!-- spring rest mvc --> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-rest-webmvc</artifactid> </dependency> <!-- dozer: dto/entity mapper --> <dependency> <groupid>net.sf.dozer</groupid> <artifactid>dozer</artifactid> <version>5.3.2</version> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> </dependency> <dependency> <groupid>joda-time</groupid> <artifactid>joda-time</artifactid> </dependency> </dependencies> <properties> <start-class>com.provider.core.application</start-class> </properties> <build> <plugins> <plugin> <artifactid>maven-compiler-plugin</artifactid> </plugin> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> <repositories> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/libs-snapshot</url> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginrepositories> <pluginrepository> <id>spring-snapshots</id> <url>http://repo.spring.io/libs-snapshot</url> <snapshots><enabled>true</enabled></snapshots> </pluginrepository> </pluginrepositories> </project>
controller
package com.provider.core; import org.dozer.dozerbeanmapper; import org.dozer.mapper; import org.slf4j.logger; import org.slf4j.loggerfactory; import org.springframework.beans.factory.annotation.autowired; import org.springframework.http.httpentity; import org.springframework.http.httpstatus; import org.springframework.http.responseentity; import org.springframework.stereotype.controller; 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.responsebody; import com.provider.account.account; import com.provider.account.accountdto; @controller public class accountcontroller { private static final logger logger = loggerfactory.getlogger(accountcontroller.class); @autowired private accountrepository repo; @requestmapping(value = "account", method = requestmethod.post) public @responsebody httpentity<accountdto> createaccount(@requestbody accountdto accountdto) { logger.info("start createaccount()"); mapper mapper = new dozerbeanmapper(); account account = mapper.map(accountdto, account.class); account savedaccount = repo.save(account); accountdto savedaccountdto = mapper.map(savedaccount, accountdto.class); // not compile "linkto" not defined. savedaccountdto.add(linkto(accountcontroller.class).slash(savedaccountdto.getid()).withselfrel()); return new responseentity<accountdto>(savedaccountdto, httpstatus.ok); } }
looks pom missing spring-hateoas
dependency.
so first add pom.xml:
<dependency> <groupid>org.springframework.hateoas</groupid> <artifactid>spring-hateoas</artifactid> <version>0.15.0.release</version> </dependency>
then can add static import , code should compile:
import static org.springframework.hateoas.mvc.controllerlinkbuilder.*
Comments
Post a Comment