Giter Club home page Giter Club logo

spring-restbucks's Introduction

Spring Restbucks

Java CI with Maven

This project is a sample implementation of the Restbucks application described in the book REST in Practice by Jim Webber, Savas Parastatidis and Ian Robinson. It's a showcase for bringing different Spring eco-system technologies together to implement a REST web service. The application uses HAL as the primary representation format. The server implementation is accompanied by a hypermedia-aware Android client that adapts to changes on the server dynamically.

Quickstart

From the command line do:

git clone https://github.com/odrotbohm/spring-restbucks.git
cd spring-restbucks/server
mvn clean package
java -jar target/*.jar

To send requests to the server application, you have several choices:

1. Use the embedded HAL Explorer.

The application ships with HAL Explorer embedded, so simply browsing to http://localhost:8080/explorer/index.html#uri=/ will allow you to explore the web service.

To get or create an order via HAL Explorer, you can start by either getting existing orders or placing a new order:

  • To get existing orders, click on the HTTP Get Request button for the restbucks:orders relation under Links. In the pop-up, click Go!, then expand any of the orders listed under Embedded Resources and click on self.
  • To place a new order, click on the HTTP Request button under the template titled Place an order under HAL-FORMS Template Elements.

Once you have an order displayed in HAL Explorer, you can submit payment:

  • Click on the HTTP Request for the template titled Go to checkout under HAL-FORMS Template Elements. This template appears for all orders with status Payment expected.
  • Enter any 16-digit number into the Credit card nuumber field and click Go!
  • You will see an error, because the card number is not in the database.
  • Enter 1234123412341234 and the payment will succeed. Ollie has got you covered :)

Note, that the curie links in the representations are currently not backed by any documents served but they will be in the future. Imagine simple HTML pages being served documenting the individual relation types.

2. Use the Android client.

Refer to the section The Android client below for more information.

IDE setup notes

Eclipse

For the usage inside an IDE do the following:

  1. Make sure you have an Eclipse with m2e installed (preferably STS).

  2. Install Lombok.

    1. Download it from the project page.
    2. Run the JAR (double click or java -jar …).
    3. Point it to your Eclipse installation, run the install.
    4. Restart Eclipse.
  3. Import the checked out code through File > Import > Existing Maven Project…

IntelliJ

  1. After opening the project in IntelliJ, right click on server/pom.xml and select Add as Maven Project.
  2. If you would like to execute tests in the Run panel (activated by right-clicking on server/src/test/java/org/springsource/restbucks and selecting Run Tests in 'restbucks'), you will need to edit Maven plugin configurations. Open the Maven tool window and find the list of plugins included in the project. Expand byte-buddy, right click on transform-extended, and select Execute After Build and Execute After Rebuild.

Project description

The project uses:

The implementation consists of mainly two parts, the order and the payment part. The Orders are exposed as REST resources using Spring Data RESTs capability to automatically expose Spring Data JPA repositories contained in the application. The Payment process and the REST application protocol described in the book are implemented manually using a Spring MVC controller (PaymentController).

Here's what the individual projects used contribute to the sample in from a high-level point of view:

Spring Data JPA

The Spring Data repository mechanism is used to reduce the effort to implement persistence for the domain objects to the declaration of an interface per aggregate root. See OrderRepository and PaymentRepository for example. Beyond that, using the repository abstract enables the Spring Data REST module to do its work.

Spring Data REST

We're using Spring Data REST to expose the OrderRepository as REST resource without additional effort.

Spring HATEOAS

Spring HATEOAS provides a generic Resource abstraction that we leverage to create hypermedia-driven representations. Spring Data REST also leverages this abstraction so that we can deploy ResourceProcessor implementations (e.g. PaymentorderResourceProcessor) to enrich the representations for Order instance with links to the PaymentController. Read more on that below in the Hypermedia section.

The final important piece is the EntityLinks abstraction that allows to create Link instance in a type-safe manner avoiding the repetition of URI templates and parts all over the place. See PaymentLinks for example usage.

Spring Plugin

The Spring Plugin library provides means to collect Spring beans by type and exposing them for selection based on a selection criterion. It basically forms the foundation for the EntityLinks mechanism provided in Spring HATEOAS and our custom extension RestResourceEntityLinks.

Spring Security / Spring Session

The spring-session branch contains additional configuration to secure the service using Spring Security, HTTP Basic authentication and Spring Session's HTTP header based session strategy to allow clients to obtain a security token via the X-Auth-Token header and using that for subsequent requests.

If you check out the branch and run the sample you should be able to follow this interaction (I am using HTTPie here)

$ http :8080
HTTP/1.1 401 Unauthorized
…
WWW-Authenticate: Basic realm="Spring RESTBucks"

You can now authenticate using the default credentials (the password password is configured in application.properties).

$ http :8080 --auth=user:password
HTTP/1.1 200 OK
Content-Type: application/hal+json;charset=UTF-8
–
X-Auth-Token: ef005d62-b69b-4675-b920-d340a238e857

Now you can use the presented auth token in further requests:

$ http :8080 X-Auth-Token:ef005d62-b69b-4675-b920-d340a238e857
HTTP/1.1 200 OK
Content-Type: application/hal+json;charset=UTF-8
–

Spring Modulith

Spring Modulith supports modular architecture in monoliths. It treats each root-level package as a separate module with top-level public members exposed as API and all other code protected as module-internal (unless explicitly specified otherwise). Through tests, it verifies compliance to modular architecture rules and also generates documentation for architecturally relevant components of the system. See DocumentationTest and also target/spring-modulith-docs/, once the test has been executed.

Additionally, we are using Spring Modulith to isolate a single module for integration testing in OrdersIntegrationTest. We are also using Spring Modulith, together with Spring Framework's in-memory messaging capabilities, to handle event-driven interactions between modules with additional support for transaction management. See the use of ApplicationModuleListener in Engine.

Finally, Spring Modulith is being used to extract distributed tracing from module interactions. To enable this functionality, see the Observability section below.

Documentation / Client Stub Generation

The restdocs branch contains the test for the order payment process augmented with setup to generate Asciidoctor snippets documenting the executed requests and expectations on the responses. These snippets are included from the general Asciidoctor documents in src/main/asciidoc, turned into HTML and packaged into the application itself during the build (run mvn clean package). The docs are then pointed to by a CURIE link in the HAL response (see Restbucks.curieProvider()) so that they appear in the docs column in the HAL browser (run mvn spring-boot:run and browse to http://localhost:8080) the service ships.

The use of the Spring Cloud Contract extension also causes WireMock stubs to be generated by those tests and placed into generated-snippets/stubs/…. The pay-order subfolder for the indivdual setups:

Open questions

  • How to package the stubs up so that they can be used by a client project?
  • How do the client tests select a particular flow to be used for stubbing?
  • How to make sure WireMock "understands" the state transitions, i.e. responses to requests to a resource changing based on intermediate requests?
  • How to set up WireMock so that the client doesn't necessarily have to select a particular flow to operate against?

Miscellaneous

The project uses Lombok to reduce the amount of boilerplate code to be written for Java entities and value objects.

Observability

The project uses Spring Modulith's observability features to inspect the runtime interaction between the logical modules of RESTBucks. To use and see this, run the application with the observability Maven profile enabled:

$ mvn spring-boot:run -Pobservability

That profile adds some dependencies, like Spring Cloud Sleuth as well as its integration with Zipkin. It also includes docker-compose support and will start Zipkin for you when the application starts. Interactions with the system will now expose the logical module invocation and their choreography.

A sample Zipkin trace

See how the triggering of the payment for an order changes the order state, kicks of the preparation engine and tweaks the order's state in turn at the start and end of the process.

Hypermedia

A core focus of this sample app is to demonstrate how easy resources can be modeled in a hypermedia driven way. There are two major aspects to this challenge in Java web-frameworks:

  1. Creating links and especially the target URL in a clean and concise way, trying to avoid the usage of Strings to define URI mappings and targets and especially the repetition of those. On the server side, we'd essentially like to express "link to the resource that manages Order instances" or "link to the resource that manages a single Order instance.

  2. Cleanly separate resource functionality implementation but still allowing to leverage hypermedia to advertise new functionality for resources as the service implementation evolves. This essentially boils down to an enrichment of resource representations with links.

In our sample the core spot these challenges occur is the payment subsystem and the PaymentController in particular.

ALPS

The repository currently contains an alps branch that is based on a feature branch of Spring Data REST to automatically expose resources that server ALPS metadata for the resources exposed.

git checkout alps
mvn spring-boot:run
curl http://localhost:8080

This will return:

{
  "_links" : {
    
    "profile" : {
      "href" : "http://localhost:8080/alps"
    }
  }
}

You can then follow the profile link to access all available ALPS resources, such as the one for orders, a link relation also listed in the response for the root resource.

Using the AOT mode for the server application

You can use Spring Native's AOT support to build the application for optimized Spring Boot startup that pre-processes the Spring configuration at runtime but still run the app as JVM application. To achieve that, run the build using the aot profile. Then activate the AOT mode of the application on startup.

$ ./mvnw -Paot
…
$ java -Dspring.aot.enabled=true -jar target/*.jar

Building native images for the server application

Make sure you have GraalVM 21+ installed (on a Mac: brew install graalvm), and your console shows the following output when running java -version:

java 21 2023-09-19
Java(TM) SE Runtime Environment Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)

The image can then be built as follows:

$ ./mvnw -Pnative

After the build has completed, start the binary:

$ ./target/spring-restbucks
…
… [           main] org.springsource.restbucks.Restbucks     : Started Restbucks in 0.366 seconds (process running for 0.446)

Using Class Data Sharing

Class Data Sharing (CDS) is an execution optimization technique available on recent JVMs (JDK 21 or newer). To make use of that make sure you have a recent JDK installed.

$ java -version
openjdk version "22" 2024-03-19
OpenJDK Runtime Environment Temurin-22+36 (build 22+36)
OpenJDK 64-Bit Server VM Temurin-22+36 (build 22+36, mixed mode)

Next, create a CDS base image for that JDK:

java -Xshare:dump

Finally, execute cds.sh located in the root of the server project. It will perform the following steps:

  1. Build the application with the AOT optimizations applied.
  2. Unpack the JAR file and create the index files necessary for CDS execution
  3. Perform an initial training run that produces the metadata file necessary for the running application.
  4. Finally, start the application in CDS-enabled mode.

You should see the startup time of the final run to roughly be half of the time the non-CDS run.

$ ./cds.sh
…
… : Started Restbucks in 1.475 seconds (process running for 1.636)

The Android client

The Android sample client can be found in android-client and is a most rudimentary implementation of a client application that leverages hypermedia elements to avoid strong coupling to the server.

Quickstart

  1. Have Android Studio installed.
  2. Import the project from android-studio.
  3. Make sure the server runs.
  4. In Android Studio, run the application in the simulator.
  5. In the application, browse existing orders, trigger payments and cancellations.

The main abstraction working with hypermedia elements is HypermediaRemoteResource. It allows to define client behavior conditionally based on the presence of links in the representations. For example, see this snippet from OrderDetailsActivity:

resource.ifPresent("restbucks:cancel") {

  with(cancel_button) {

    visibility = View.VISIBLE

    setOnClickListener {

      CancelOrder(Link(selfUri)).execute().get()

      it.context.startActivity(Intent(it.context, MainActivity::class.java))
    }
  }
}

The closure is only executed if the link with a relation restbucks:cancel is actually present. It then enables the button and registers CancelOrder action for execution on invocation.

TODO - complete

spring-restbucks's People

Contributors

christophstrobl avatar ciberkleid avatar fvarg00 avatar mirzmaster avatar mjkrumlauf avatar odrotbohm avatar pfichtner avatar snicoll avatar wilkinsona avatar yejianfengblue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-restbucks's Issues

Submitting Money input via HAL browser broken

Hi Oliver,

I have to bug you again for the REST API of money values. Polishing of my pull request (specifically https://github.com/olivergierke/spring-restbucks/blob/master/src/main/java/org/springsource/restbucks/JacksonCustomizations.java#L188) introduces LocaleContextHolder.getLocale() to obtain a money parser for a given locale. This does not fit anymore with the other part of the code (lines 123 ff) where you provide a regular expression pattern for the money value.

E.g. given locale "de-DE", I am expected to provide a money value like this: "EUR 123,45", which is rejected by the input validation inside the HAL browser (taking the regex from json schema iirc). So either stick to a fixed locale (I was using Locale.US in my PR, and that matches your regex), or remove the regular expression validation.

If you want, I can provide a test case that reproduces the bug.

Failing tests

I have 8 failing tests on Linux

Here is a failing test's stack trace

org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select order0_.id as id1_3_0_, order0_.location as location2_3_0_, order0_.ordered_date as ordered_3_3_0_, order0_.status as status4_3_0_ from rborder order0_ where order0_.id=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.SchemaManager.getTable(Unknown Source)
    at org.hsqldb.ParserDQL.readTableName(Unknown Source)
    at org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
    at org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
    at org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
    at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
    at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
    at org.hsqldb.Session.compileStatement(Unknown Source)
    at org.hsqldb.StatementManager.compile(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
    at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
    at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
    at com.sun.proxy.$Proxy46.prepareStatement(Unknown Source)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:162)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.prepareQueryStatement(AbstractLoadPlanBasedLoader.java:257)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:201)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:137)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)
    at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:186)
    at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4126)
    at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:502)
    at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:467)
    at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212)
    at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274)
    at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)
    at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070)
    at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176)
    at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2551)
    at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1110)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1074)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:289)
    at com.sun.proxy.$Proxy72.find(Unknown Source)
    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findOne(SimpleJpaRepository.java:226)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:443)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:428)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:382)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodInterceptor.invoke(RepositoryFactorySupport.java:513)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy75.findOne(Unknown Source)
    at org.springsource.restbucks.payment.PaymentServiceIntegrationTest.marksOrderAsPaid(PaymentServiceIntegrationTest.java:42)

Problems in README

Just a heads up, not sure this is the proper venue but your link to Lombok in the instructions is using a relative URL that 404's

https://github.com/olivergierke/spring-restbucks

"2. Install Lombok."

In addition I'm trying to setup this project in eclipse, and not sure how to build it in Maven. I usually use Gradle. If there was just a little step somewhere near the end on running the project to know it's working that'd be very helpful.

Race condition on executing tests

When running tests in this order:
-Dtest=OrderRepositoryIntegrationTest,ApplicationIntegrationTest,CreditCardRepositoryIntegrationTest

I get an error:
CreditCardRepositoryIntegrationTest.createsCreditCard:41 » InvalidDataAccessResourceUsage

Cause is a JPA resource which is not cleaned up after OrderRepositoryIntegrationTest.
As workaround I added
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
to the OrderRepositoryIntegrationTest, but I'm sure you'll find a better solution for that :-)

Here is the test run output:
http://paste.scsys.co.uk/498717

Executed with:
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:37+02:00)
Maven home: /home/tf/ENV/apache-maven-3.3.3
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-61-generic", arch: "amd64", family: "unix"

CurieProvider assumes port 8080

If the app is run on a different port, the documentation CURIEs are all incorrect, e.g.:

java -Dserver.port=9999 -jar target/restbucks-1.0.0.BUILD-SNAPSHOT.war

{
  "_links": {
    "restbucks:orders": {
      "href": "http://localhost:9999/orders{?page,size,sort,projection}",
      "templated": true
    },
    "restbucks:engine": {
      "href": "http://localhost:9999/engine"
    },
    "restbucks:pages": {
      "href": "http://localhost:9999/pages"
    },
    "profile": {
      "href": "http://localhost:9999/alps"
    },
    "curies": [
      {
        "href": "http://localhost:8080/alps/{rel}",
        "name": "restbucks",
        "templated": true
      }
    ]
  }
}

Embedded resources not correctly rendering in HAL

When I configure my app with @EnableHypermediaSupport(HAL), I would expect that links within the _embedded object should start be named _links, but instead they appear to be rendered using the default (i.e. without the underscore, a.k.a Atom style).

{
...
  "_embedded" : {
    "orders" : [ {
      "status" : "PAYMENT_EXPECTED",
      "location" : "TAKE_AWAY",
      "orderedDate" : 1382146057073,
      "links" : [ {
        "href" : "http://localhost:8080/api/orders/1"
      }, {
        "href" : "http://localhost:8080/api/orders/1"
      }, {
        "href" : "http://localhost:8080/api/orders/1"
      }, {
        "href" : "http://localhost:8080/api/orders/1/payment"
      } ]
...
    }
}

Question: Consuming Web Service from other application

In the past, with SOAP webservice a wsdl would be exposed for another application to be able to generate the classes to create a web service client. Since this is not a SOAP service, it is a REST service how could another developer quickly create a client application using this REST service. The calling application could be in .net or java.

It seems like you would want to allow for some reuse and package up the entity class in a separate library.

No links available when running with Spring Boot 1.4.0.RELEASE

No links are shown for the root resource in the hal-browser
when running spring-restbucks with Spring Boot 1.4.0.RELEASE.

Wanted to use this as an example for real REST APIs with Spring Boot 1.4.0.RELEASE.
Got it working (with a quick hack) by only redirecting requests to the hal-browser that are not requests for application/hal+json via headers={"!Accept=*application/hal+json*"}.
in org.springframework.data.rest.webmvc.halbrowser.HalBrowser.

    @RequestMapping(value = { "/", "" }, method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE, headers={"!Accept=*application/hal+json*"})
    public View index(HttpServletRequest request) {
        return getRedirectView(request, false);
    }

Problem during "mvn test": Tests run: 31, Failures: 1, Errors: 2, Skipped: 1

Hi!
There is a problem when running "mvn test" (jdk1.8.0_20).
It says:
"EngineControllerIntegrationTests.customControllerReturnsDefaultMediaType:51 Content type [application/schema+json] is not compatible with [application/hal+json]"
PaymentProcessIntegrationTest.processNewOrder:88->triggerPayment:226 » NullPointer
PaymentProcessIntegrationTest.processExistingOrder:72->triggerPayment:226 » NullPointer"

Here is a more complete log sequence:

"2014-10-19 17:42:17,155 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 425 - HHH000389: Unsuccessful: alter table payment drop constraint FK_dmmuiy41quxpiuma1f9cbin4r
2014-10-19 17:42:17,155 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 425 - HHH000389: Unsuccessful: alter table payment drop constraint FK_hopdj6iwtpavr7f7ad7jjixtc
2014-10-19 17:42:17,155 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 426 - user lacks privilege or object not found: PUBLIC.PAYMENT
2014-10-19 17:42:17,156 INFO o.s.w.context.support.GenericWebApplicationContext: 873 - Closing org.springframework.web.context.support.GenericWebApplicationContext@5c0f74: startup date [Sun Oct 19 17:42:17 CEST 2014]; root of context hierarchy
2014-10-19 17:42:17,156 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 426 - user lacks privilege or object not found: PUBLIC.PAYMENT
2014-10-19 17:42:17,156 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 425 - HHH000389: Unsuccessful: alter table rborder_items drop constraint FK_t84h47387aak87l7x0we7guw3
2014-10-19 17:42:17,157 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 425 - HHH000389: Unsuccessful: alter table payment drop constraint FK_dmmuiy41quxpiuma1f9cbin4r
2014-10-19 17:42:17,157 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 426 - user lacks privilege or object not found: PUBLIC.RBORDER_ITEMS
2014-10-19 17:42:17,158 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 426 - user lacks privilege or object not found: PUBLIC.PAYMENT
2014-10-19 17:42:17,158 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 425 - HHH000389: Unsuccessful: alter table rborder_items drop constraint FK_mhx71xvo1l4va0jhqvsx42fe1
2014-10-19 17:42:17,161 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 425 - HHH000389: Unsuccessful: alter table rborder_items drop constraint FK_t84h47387aak87l7x0we7guw3
2014-10-19 17:42:17,162 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 426 - user lacks privilege or object not found: PUBLIC.RBORDER_ITEMS
2014-10-19 17:42:17,162 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 426 - user lacks privilege or object not found: PUBLIC.RBORDER_ITEMS
2014-10-19 17:42:17,163 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 425 - HHH000389: Unsuccessful: alter table rborder_items drop constraint FK_mhx71xvo1l4va0jhqvsx42fe1
2014-10-19 17:42:17,163 ERROR org.hibernate.tool.hbm2ddl.SchemaExport: 426 - user lacks privilege or object not found: PUBLIC.RBORDER_ITEMS

Results :

Failed tests:
EngineControllerIntegrationTests.customControllerReturnsDefaultMediaType:51 Content type [application/schema+json] is not compatible with [application/hal+json]

Tests in error:
PaymentProcessIntegrationTest.processNewOrder:88->triggerPayment:226 » NullPointer
PaymentProcessIntegrationTest.processExistingOrder:72->triggerPayment:226 » NullPointer

Tests run: 31, Failures: 1, Errors: 2, Skipped: 1"

Regards & viele Grüße,
Khalid

Integrate Spring-RESTDocs

I think this project is a prime example for showcasing the power of documenting the rest api with spring restdocs. What do you think?

HTTP Status 500 - No WebApplicationContext found

Edit : It's not clear in the readme how to modify this project to deploy it to a servlet container like Tomcat...
It would be great to outline how to run it in the readme with mvn jetty:run and what to modify if serving it in a container like Tomcat.

When I deploy the project with a blank web.xml manually added to the war I get this :

HTTP Status 500 - No WebApplicationContext found: no ContextLoaderListener registered?

type Exception report

message No WebApplicationContext found: no ContextLoaderListener registered?

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.lookupEntityManagerFactory(OpenEntityManagerInViewFilter.java:216)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.lookupEntityManagerFactory(OpenEntityManagerInViewFilter.java:203)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:148)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)

get a weird error org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.AbstractMethodError: while running the boot app

Hi I might be missing something here but I get this error when I do a mvn spring-boot:run or run the test case customControllerReturnsDefaultMediaType

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.AbstractMethodError: com.fasterxml.jackson.databind.JsonSerializer.isEmpty(Ljava/lang/Object;)Z
    at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1303)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
    at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:65)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:167)
    at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:134)
    at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:144)
    at org.springsource.restbucks.engine.web.EngineControllerIntegrationTests.customControllerReturnsDefaultMediaType(EngineControllerIntegrationTests.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:85)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:86)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:243)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:182)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.AbstractMethodError: com.fasterxml.jackson.databind.JsonSerializer.isEmpty(Ljava/lang/Object;)Z
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:489)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:639)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:128)
    at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:1902)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:244)
    at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:212)
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:157)
    at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:186)
    at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71)
    at org.springframework.data.rest.webmvc.ResourceProcessorHandlerMethodReturnValueHandler.handleReturnValue(ResourceProcessorHandlerMethodReturnValueHandler.java:174)
    at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:127)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:799)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:728)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    ... 41 more

any idea ,or is it some jar issue ?

Strange behavior of a projection

Hi,
I've found a small problem with OrderProjection. If GET request is /orders?projection=summary, there'll be the next response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/orders?projection=summary{&page,size,sort}",
      "templated": true
    },
    "search": {
      "href": "http://localhost:8080/orders/search"
    }
  },
  "_embedded": {
    "$Proxy93s": [
      {
        "orderedDate": "2014-05-21T18:24:33.168Z",
        "status": "PAYMENT_EXPECTED",
        "_links": {
          "self": {
            "href": "http://localhost:8080/orders/1{?projection}",
            "templated": true
          }
        }
      },
      {
        "orderedDate": "2014-05-21T18:24:33.168Z",
        "status": "PAYMENT_EXPECTED",
        "_links": {
          "self": {
            "href": "http://localhost:8080/orders/2{?projection}",
            "templated": true
          }
        }
      }
    ]
  },
  "page": {
    "size": 20,
    "totalElements": 2,
    "totalPages": 1,
    "number": 0
  }
}

I'd like to bring the name of an embedded relation to your attention. It's $Proxy93s instead of orders.

Thanks

Application startup failed InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select count(*) as col_0_0_ from rborder order0_]

Entered:

java -jar target/restbucks-1.0.0.BUILD-SNAPSHOT.war

got:

2014-05-30 10:12:28,443 ERROR         org.springframework.boot.SpringApplication: 331 - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderInitializer' defined in URL [jar:file:C:/ws/ws-spring-restbucks/spring-restbucks/target/restbucks-1.0.0.BUILD-SNAPSHOT.war!/WEB-INF/classes!/org/springsource/restbucks/order/OrderInitializer.class]: Instantiation
of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springsource.restbucks.order.OrderInitializer]: Constructor threw exception; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select count(*) as col_0_0_ from rborder order0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:278) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120) ~[spring-boot-1.1.0.M2.jar!/:1.1.0.M2]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:683) [spring-boot-1.1.0.M2.jar!/:1.1.0.M2]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.1.0.M2.jar!/:1.1.0.M2]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:944) [spring-boot-1.1.0.M2.jar!/:1.1.0.M2]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:933) [spring-boot-1.1.0.M2.jar!/:1.1.0.M2]
        at org.springsource.restbucks.Restbucks.main(Restbucks.java:52) [classes!/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_51]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53) [restbucks-1.0.0.BUILD-SNAPSHOT.war:na]
        at java.lang.Thread.run(Unknown Source) [na:1.7.0_51]
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springsource.restbucks.order.OrderInitializer]: Constructor threw exception; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select
count(*) as col_0_0_ from rborder order0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:125) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:270) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        ... 23 common frames omitted
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select count(*) as col_0_0_ from rborder order0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:172) ~[spring-orm-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:155) ~[spring-orm-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417) ~[spring-orm-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111) ~[spring-data-jpa-1.6.0.RELEASE.jar!/:na]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at com.sun.proxy.$Proxy81.count(Unknown Source) ~[na:na]
        at org.springsource.restbucks.order.OrderInitializer.<init>(OrderInitializer.java:45) ~[classes!/:na]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_51]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.7.0_51]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.7.0_51]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.7.0_51]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) ~[spring-beans-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        ... 25 common frames omitted
Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
        at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:196) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1884) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1861) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.doQuery(Loader.java:909) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.doList(Loader.java:2551) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.doList(Loader.java:2537) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.Loader.list(Loader.java:2362) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:496) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:229) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1260) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573) ~[hibernate-entitymanager-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:495) ~[hibernate-entitymanager-4.3.1.Final.jar!/:4.3.1.Final]
        at org.springframework.data.jpa.repository.support.SimpleJpaRepository.count(SimpleJpaRepository.java:357) ~[spring-data-jpa-1.6.0.RELEASE.jar!/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_51]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:405) ~[spring-data-commons-1.8.0.RELEASE.jar!/:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:390) ~[spring-data-commons-1.8.0.RELEASE.jar!/:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:344) ~[spring-data-commons-1.8.0.RELEASE.jar!/:na]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) ~[spring-tx-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) ~[spring-tx-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.0.5.RELEASE.jar!/:4.0.5.RELEASE]
        ... 38 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: RBORDER
        at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb-2.3.2.jar!/:2.3.2]
        at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) ~[hsqldb-2.3.2.jar!/:2.3.2]
        at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source) ~[hsqldb-2.3.2.jar!/:2.3.2]
        at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source) ~[hsqldb-2.3.2.jar!/:2.3.2]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_51]
        at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126) ~[tomcat-jdbc-7.0.53.jar!/:na]
        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109) ~[tomcat-jdbc-7.0.53.jar!/:na]
        at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80) ~[tomcat-jdbc-7.0.53.jar!/:na]
        at com.sun.proxy.$Proxy55.prepareStatement(Unknown Source) ~[na:na]
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:162) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186) ~[hibernate-core-4.3.1.Final.jar!/:4.3.1.Final]
        ... 69 common frames omitted

Validation beforeSave* is not working (but beforeCreate* is working)

Hi Oliver
I was trying to add validation in the same project, but it didn't worked properly.
When I give bean name as beforeSaveItemValidator its not working, eventhough beforeCreateItemValidator is working as expected.
Can you please help me, or can you add validation in this restbucks project.

Here is the output

When bean is beforeCreateItemValidator()

Validation is working ---> 400 Bad Request

curl -v -X POST -H "Content-Type: application/json" -d '{ "id" :4, "quantity" : 44 }' http://localhost:8080/item/

  • About to connect() to localhost port 8080
  • Trying 127.0.0.1... connected
  • Connected to localhost (127.0.0.1) port 8080

    POST /item/ HTTP/1.1
    User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: localhost:8080
    Accept: /
    Content-Type: application/json
    Content-Length: 28

    { "id" :4, "quantity" : 44 }HTTP/1.1 400 Bad Request
    < Content-Type: application/json
    < Transfer-Encoding: chunked
    < Server: Jetty(8.1.9.v20130131)

  • Connection #0 to host localhost left intact
  • Closing connection #0
    {"errors":[{"entity":"Item","message":"Item name required","invalidValue":"null","property":"name"}]}

but When bean is beforeSaveItemValidator()

Validation is not working ---> 201 Created

curl -v -X POST -H "Content-Type: application/json" -d '{ "id" :4, "quantity" : 44 }' http://localhost:8080/item/

  • About to connect() to localhost port 8080
  • Trying 127.0.0.1... connected
  • Connected to localhost (127.0.0.1) port 8080

    POST /item/ HTTP/1.1
    User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: localhost:8080
    Accept: /
    Content-Type: application/json
    Content-Length: 28

    { "id" :4, "quantity" : 44 }HTTP/1.1 201 Created
    < Location: http://localhost:8080/item/3
    < Content-Length: 0
    < Server: Jetty(8.1.9.v20130131)

  • Connection #0 to host localhost left intact
  • Closing connection #0

You can get the changes here

https://github.com/guptasujeet/spring-restbucks.git

example process flow

As a software developer I would like to play the process flow. This would enable me to give a demo of spring-data-rest to our team of developers.

Maybe it is a nice enhancement to document this flow, e.g. in the README.md

Kind regards

Hugo

POSTing of new order fails

With the current snapshot I cannot post new orders. In the HAL Browser all fields are disabled and show a red warning sign when hovering over them.
When posting this manually:

{
"lineItems": [
    {
        "quantity": 1,
        "size": "Gross",
        "price": "EUR 2.80",
        "name": "Cappuccino",
        "milk": "Vollmilch"
    }
],
"price": "",
"location": "Zum mitnehmen",
"orderedDate": "",
"status": "Zu zahlen"
}

I get:

{
"cause": {
    "cause": {
        "cause": null,
        "message": "Argument #0 of constructor [constructor for org.springsource.restbucks.order.Order, annotations: {interface com.fasterxml.jackson.annotation.JsonCreator=@com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)}] has no property name annotation; must have name when multiple-parameter constructor annotated as Creator"
    },
    "message": "Argument #0 of constructor [constructor for org.springsource.restbucks.order.Order, annotations: {interface com.fasterxml.jackson.annotation.JsonCreator=@com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)}] has no property name annotation; must have name when multiple-parameter constructor annotated as Creator"
},
"message": "Could not read document: Argument #0 of constructor [constructor for org.springsource.restbucks.order.Order, annotations: {interface com.fasterxml.jackson.annotation.JsonCreator=@com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)}] has no property name annotation; must have name when multiple-parameter constructor annotated as Creator; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Argument #0 of constructor [constructor for org.springsource.restbucks.order.Order, annotations: {interface com.fasterxml.jackson.annotation.JsonCreator=@com.fasterxml.jackson.annotation.JsonCreator(mode=DEFAULT)}] has no property name annotation; must have name when multiple-parameter constructor annotated as Creator"
}

Dependency on spring-hateoas 0.17.0.BUILD-SNAPSHOT (TypeConstrainedMappingJackson2HttpMessageConverter)?

The project did not run failing with a ClassNotFoundException:

Caused by: java.lang.ClassNotFoundException: org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more

Turned out the class is indeed not available for spring-hateoas 0.15.0.RELEASE, but it is available 0.17.0.BUILD-SNAPSHOT (maybe earlier). Could it be that the pom.xml of spring-restbucks needs to be updated with the right version?

Exception while running mvn clean package

I followed the instructions to build and get the project running and got this exception. I also tried deploying the project on tomcat (from within eclipse) and I got the same exception there as well.

Caused by: java.lang.NoSuchMethodError: org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.config()Lorg/springframework/data/rest/core/config/RepositoryRestConfiguration;
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration.config(SpringBootRepositoryRestMvcConfiguration.java:50)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$d9d8d7fc.CGLIB$config$1()
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$d9d8d7fc$$FastClassBySpringCGLIB$$56fe9577.invoke()

Update:
Here is the jar which contains this class (its version is 2.4.0) and this version does not contain any method called config() for this class.
screen shot 2015-05-16 at 9 22 02 pm

Also, it seems that maven is managing its version from 2.2.2 to 2.4.0
screen shot 2015-05-16 at 9 22 46 pm

The import UriTemplate cannot be resolved (just update spring-hateoas to 0.10.0.BUILD-SNAPSHOT)

The import org.springframework.hateoas.UriTemplate cannot be resolved at Restbucks.java: /restbucks/src/main/java/org/springsource/restbucks (line 29)

It's due the spring-hateoas dependency: currently 0.9.0.BUILD-SNAPSHOT, but it has to be 0.10.0.BUILD-SNAPSHOT

After updating, the project compiles, but there are 3 failures:

Test set: org.springsource.restbucks.engine.web.EngineControllerIntegrationTests:

  1. java.lang.AssertionError: Content type [application/schema+json] is not compatible with [application/hal+json](line 50)

Test set: org.springsource.restbucks.payment.web.PaymentProcessIntegrationTest

  1. java.lang.AssertionError: Status expected:<201> but was:<415> (line 225)
  2. java.lang.AssertionError: Status expected:<201> but was:<415> (line 225)

Project Build on my Mac computers only with Maven command line and not with STS

Hi Ollie,

this nice and interesting example doesn't work for me on my Mac computer's in STS like expected.

When I checkout the sources with STS (3.1 or 3.2) and the m2e-egit plugin, I first have the problem that doesn't have the Java 7 installed on my system and receive the error while executing the project on vFabric 'Error Project facet Java version 1.7 is not supported.'

Then when I install the Java SE JDK 1.7 from oracle on my system and change the settings in STS, all files many files get red in the IDE.

Do you have any Idea what could be the problem?

Which STS Version, which Maven Version and JDK Version you use? Because with the command line tool from maven it works like a charm, I even can start the server with an jetty.

Greetings and Thanks for your answer

Tommy

Bildschirmfoto 2012-12-18 um 20 01 54

/{repository}/schema - spring-data-rest 2.0.0

URI /{repository}/schema in spring-data-rest 1.1.0M1 is a very nice feature. However I see the same is missing in spring-data-rest- 2.0.0-BUILD-SNAPSHOT. Is that not officially supported feature?

Trying this repository with MySQL as database service

Hey @olivergierke ,
I am trying to configure MySQL database with this repository. To do that I have tried some things mentioned below:
pom.xml:

      <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

and In application.properties:
spring.jpa.generate-ddl=true

server.port=8080

dialect=org.hibernate.dialect.MySQL5InnoDBDialect

spring.datasource.url=jdbc:mysql://localhost/restBucks

spring.datasource.driverClassName=com.mysql.jdbc.Driver

spring.datasource.username=root

spring.datasource.password=root

but I am facing about 15 errors with title of "beanCreationException". you can see my post on stackoverflow at:
http://stackoverflow.com/questions/25930191/connect-mysql-to-spring-application

can you please suggest/guide me how to achieve this?
Thanks

JUnit errors in *IntegrationTest

Hi,

though the restbucks application is running fine as spring boot app running mvn clean package results in 5 errors in the JUnit test cases:

$ mvn clean package

...

Results :

Tests in error:
  EngineControllerIntegrationTests.customControllerReturnsDefaultMediaType:42 ╗ IllegalState
  OrderResourceIntegrationTest.exposesOrdersResourceViaRootResource:41 ╗ IllegalState
  PaymentProcessIntegrationTest.processNewOrder:85->accessRootResource:117 ╗ IllegalState
  PaymentProcessIntegrationTest.processExistingOrder:68->accessRootResource:117 ╗ IllegalState
  PaymentProcessIntegrationTest.cancelOrderBeforePayment:101->accessRootResource:117 ╗ IllegalState

with the following StackTrace (same for every failure of the above):

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:89)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.lookupEntityManagerFactory(OpenEntityManagerInViewFilter.java:215)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.lookupEntityManagerFactory(OpenEntityManagerInViewFilter.java:202)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:137)
    at org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:73)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:137)
    at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:141)
    at org.springsource.restbucks.order.web.OrderResourceIntegrationTest.exposesOrdersResourceViaRootResource(OrderResourceIntegrationTest.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Seems like MockMVC in Combination with OpenSessionInViewFilter causes some problems.

Best
Michael

Problem with dependency's for org.springframework.data

Hi Oliver,

Nice example!

I have downloaded and installed the project as you instructed installing lombok and adding the jar file to the project. I'm using STS.

I'm having problems with some of my pom file dependency's for org.springframework.data. I'm just wondering if i'm missing something any help would be much appreciated.

Below are screen shots of the error in my pom file

MissingDependencies

pomfile

Thanks and regards
David

Maven build failed to find dependencies

Getting this error on a fresh git pull :

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4:15.477s
[INFO] Finished at: Sat Nov 23 11:45:33 PST 2013
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project restbucks: Could not resolve dependencies for project org.springsource.restbucks:restbucks:war:1.0.0.BUILD-SNAPSHOT: Could not find artifact org.springframework.data:spring-data-commons:jar:1.7.0.BUILD-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

org.springframework.data.mapping.PropertyReferenceException: No property der found for type org.springsource.restbucks.payment.Payment

I cloned and executed mvn jetty:run as instructed, and I get this error (among other things):
org.springframework.data.mapping.PropertyReferenceException: No property der found for type org.springsource.restbucks.payment.Payment

When creating the implementation for the PaymentRepository interface and resolving which property to map to "Payment findByOrder(Order order);", it seems that spring data is chopping off "findByOr" instead of "findBy", leaving only "der", hence the "no der" property error. I wonder if this is a bug with spring data...

My environment -
OS: Mac OS X (10.8.2),
JDK: Oracle JDK 7
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.