GithubHelp home page GithubHelp logo

gothinkster / spring-boot-realworld-example-app Goto Github PK

View Code? Open in Web Editor NEW
1.3K 56.0 662.0 759 KB

Example Spring codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld API spec.

License: MIT License

Java 100.00%
spring-boot realworld mybatis

spring-boot-realworld-example-app's Introduction

RealWorld Example App using Kotlin and Spring

Actions

Spring boot + MyBatis codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

This codebase was created to demonstrate a fully fledged full-stack application built with Spring boot + Mybatis including CRUD operations, authentication, routing, pagination, and more.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

NEW GraphQL Support

Following some DDD principles. REST or GraphQL is just a kind of adapter. And the domain layer will be consistent all the time. So this repository implement GraphQL and REST at the same time.

The GraphQL schema is https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/resources/schema/schema.graphqls and the visualization looks like below.

And this implementation is using dgs-framework which is a quite new java graphql server framework.

How it works

The application uses Spring Boot (Web, Mybatis).

  • Use the idea of Domain Driven Design to separate the business term and infrastructure term.
  • Use MyBatis to implement the Data Mapper pattern for persistence.
  • Use CQRS pattern to separate the read model and write model.

And the code is organized as this:

  1. api is the web layer implemented by Spring MVC
  2. core is the business model including entities and services
  3. application is the high-level services for querying the data transfer objects
  4. infrastructure contains all the implementation classes as the technique details

Security

Integration with Spring Security and add other filter for jwt token process.

The secret key is stored in application.properties.

Database

It uses a H2 in-memory database sqlite database (for easy local test without losing test data after every restart), can be changed easily in the application.properties for any other database.

Getting started

You'll need Java 11 installed.

./gradlew bootRun

To test that it works, open a browser tab at http://localhost:8080/tags .
Alternatively, you can run

curl http://localhost:8080/tags

Try it out with Docker

You'll need Docker installed.

./gradlew bootBuildImage --imageName spring-boot-realworld-example-app
docker run -p 8081:8080 spring-boot-realworld-example-app

Try it out with a RealWorld frontend

The entry point address of the backend API is at http://localhost:8080, not http://localhost:8080/api as some of the frontend documentation suggests.

Run test

The repository contains a lot of test cases to cover both api test and repository test.

./gradlew test

Code format

Use spotless for code format.

./gradlew spotlessJavaApply

Help

Please fork and PR to improve the project.

spring-boot-realworld-example-app's People

Contributors

aisensiy avatar callmemarv avatar darioseidl avatar eugenesimakin avatar gfecher avatar jsmenzies avatar jws1837 avatar kazuki43zoo avatar medchiboub avatar ramazansakin avatar robertglenn avatar vileneera avatar vitalyster 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

spring-boot-realworld-example-app's Issues

HTTP ERROR 401

With

./gradlew bootRun
open http://localhost:8080

I get "HTTP ERROR 401" in the browser.
What do I do wrong?

Docker build failed

Hi folks,

I was trying to build the project with docker to push the image to a docker repo but the build failed:

Sending build context to Docker daemon  981.5kB
Step 1/12 : FROM gradle:jdk-alpine
 ---> 8017d8c2ba74
Step 2/12 : WORKDIR /home/gradle/project
 ---> Using cache
 ---> d3b9d5f4da94
Step 3/12 : EXPOSE 8080
 ---> Using cache
 ---> 64b5d259408a
Step 4/12 : USER root
 ---> Using cache
 ---> 4b54f6919a92
Step 5/12 : RUN apk update
 ---> Using cache
 ---> aff74c308198
Step 6/12 : ENV GRADLE_USER_HOME /home/gradle/project
 ---> Using cache
 ---> 961419bda82f
Step 7/12 : COPY . /home/gradle/project
 ---> 20280f86bff9
Step 8/12 : RUN gradle build
 ---> Running in f89f3fc54e02

Welcome to Gradle 5.4.1!

Here are the highlights of this release:
 - Run builds with JDK12
 - New API for Incremental Tasks
 - Updates to native projects, including Swift 5 support

For more details see https://docs.gradle.org/5.4.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* Where:
Build file '/home/gradle/project/build.gradle' line: 2

* What went wrong:
An exception occurred applying plugin request [id: 'org.springframework.boot', version: '2.3.4.RELEASE']
> Failed to apply plugin [id 'org.springframework.boot']
   > Spring Boot plugin requires Gradle 5 (5.6.x only) or Gradle 6 (6.3 or later). The current version is Gradle 5.4.1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s

Environment:
OS: Ubuntu 20.04
Docker version: 20.10.1, build 831ebea

Updating article title causes internal server error

Updating the title of an article updates the slug in the background. The update endpoint then tries to retrieve the updated article using the old slug which results in an internal server error.

I created a pull request that fixes the problem by using the updated slug instead.
#37

Login mutation doesn't work

If I use the login mutation under UserMutation, it works fine. But protected mutations like createArticle still don't work, throwing Authentication exception. The code itself also doesn't send out a JWT token on login. What could be the issue?

Could not find snakeyaml-1.27-android.jar (org.yaml:snakeyaml:1.27)

./gradlew bootJar

* What went wrong:
Execution failed for task ':bootJarMainClassName'.
> Could not find snakeyaml-1.27-android.jar (org.yaml:snakeyaml:1.27).
  Searched in the following locations:
      file:/home/vmihailenco/.m2/repository/org/yaml/snakeyaml/1.27/snakeyaml-1.27-android.jar

Adding the v1.28 as a dependency to build.gradle fixes the problem for me

implementation 'org.yaml:snakeyaml:1.28'

Googling says that this is caused by incorrect classifier (android) in 1.27 version...

401 error on login

I get a 401 error code when logging in, how do I use the JWT secret key provided in application.properties file?

Extra collection of tags into Set

[https://github.com/gothinkster/spring-boot-realworld-example-app/blob/master/src/main/java/io/spring/core/article/Article.java] Article

core.article package in Article class constructor, you have collected Tags in the Set then immediately collected them into a List.
Is there a good reason for that? If it's for shuffling, it's better to use Collections.shuffle().

Postman 401

401 when posting a user registration using the realworld.io postman collection.

Missing or nolicense

Can you please include your chosen LICENSE.md file. I can't legally use your work unless you allow me to. I think it is only fair to assume that you wanted to publish this work with the same MIT license that you used on the realworld.io repo (https://github.com/gothinkster/realworld).

Problem with jwt auth

Hi all!
I have tried to set up the realworld example putting together Aurelia.io front end + Spring-boot. I have changed the application.properties in this way:

server.port: 3000
management.server.port: 3001
management.server.address: 127.0.0.1

because the default 8080 was already busy. Starting the application, I get the error below but I wasn't able to figure out why. It seems that front end is trying to talk in https with an http backend but I have not found in the documentation any reference about an https setting of Spring boot. For sure I'm not understanding how to deal with jwt auth but I do not what.

Thanks in advance!

2018-10-09 23:19:18.060 DEBUG 12424 --- [nio-3000-exec-3] o.a.tomcat.util.net.SocketWrapperBase : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@79d7edb9:org.apache.tomcat.util.net.NioChannel@39a1e54c:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:3000 remote=/0:0:0:0:0:0:0:1:37248]], Read from buffer: [0]
2018-10-09 23:19:18.060 DEBUG 12424 --- [nio-3000-exec-3] o.a.coyote.http11.Http11InputBuffer : Received [���Ã�¿��æµn=/ŧ�/5
�z

ÿ��
��������������ost�#
�hhttp/1.1
��

���������zz�]
2018-10-09 23:19:18.060 DEBUG 12424 --- [nio-3000-exec-3] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header

java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:426) ~[tomcat-embed-core-8.5.28.jar:8.5.28]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687) ~[tomcat-embed-core-8.5.28.jar:8.5.28]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.28.jar:8.5.28]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.28.jar:8.5.28]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.28.jar:8.5.28]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.28.jar:8.5.28]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_20]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_20]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.28.jar:8.5.28]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_20]

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.