/url-shortener

yet another URL-shortener with UI

Primary LanguageJava

Url Shortener project based on spring boot [power off]

Tip
It’s possible to use emojis as admonition icons on GitHub.

1. Requirements

  1. Git

  2. Java JDK 11

  3. Apache Maven

2. Spring Boot Tutorials [fire]

  1. API documentation for the project located here http://localhost:8080/doc

3. Docker Image

  1. Package jar file mvn clean package

  2. Build image docker build . --tag url-shortener or docker build --no-cache -t url-shortener .

  3. Build image docker build . --tag url-shortener:1.0 with version (image tag)

  4. Run docker image docker run -it -p 8080:8080 url-shortener:latest

  5. Run with Spring profile docker run -e "SPRING_PROFILES_ACTIVE=prod" -p 8085:8085 -t url-shortener

  6. ./gradlew wrapper --gradle-version 6.2.2 Update gradle version

docker run -rm -e "SPRING_PROFILES_ACTIVE=dev" -p 8080:8080 -t url-shortener

  1. run jar local java -Dspring.profiles.active=prod -jar target/url-shortener-1.0.0-SNAPSHOT.jar

FROM adoptopenjdk/openjdk11:alpine-slim as build
WORKDIR /workspace/app

COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src

RUN ./mvnw install -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

FROM adoptopenjdk/openjdk11:alpine-jre
VOLUME /tmp
ARG DEPENDENCY=/workspace/app/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","-Dspring.profiles.active=prod","se.techinsight.Application"]

4. Packaging OCI Images, Layered Jars

  1. link to the documentation

  2. https://ostechnix.com/how-to-analyze-and-explore-the-contents-of-docker-images/

  3. run command

    mvn clean spring-boot:build-image
    docker run -it -p80:8080 url-shortener:1.0.0-SNAPSHOT
    curl -s http://localhost:80/actuator/info | jq .
    {
      "app": {
        "name": "url-shortener-service",
        "description": "URL Shortener on Spring Boot",
        "version": "1.0.0-SNAPSHOT"
      },
      "env": {
        "java": {
          "vendor": "Oracle Corporation",
          "vm-name": "OpenJDK 64-Bit Server VM",
          "runtime-version": "11.0.4+11"
        }
      },
      "context": {
        "bean-definition-count": 387,
        "startup-date": 1599166535710
      }
    }

5. Actuator service

pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

6. Template Engines

  1. FreeMarker

  2. Groovy Templates

  3. Thymeleaf

  4. Velocity

  5. Mustache

  6. GSP = Groovy Server Pages

7. Data base changing

  1. LiquiBase (free and Easily rollback changes)

  2. Flyway (payable for rollback)

8. Springdoc OpenAPI

# swagger-ui custom path
springdoc.swagger-ui.path=/doc

open in browser http://localhost:8080/doc for documentation,

There are 2 versions of Open API documentaiton
  1. http://localhost:8080/v2/api-docs used only for testing purposes

  2. http://localhost:8080/v3/api-docs

9. Add maven wrapper

mvn --version
mvn -N io.takari:maven:wrapper
mvn -N io.takari:maven:wrapper -Dmaven=3.6.3

10. Spring Boot family

Spring Family

11. Open API 2 (Swagger2) to 3 Converter

Spring Family

12. Section for testing ascii-doc [info circle]

  • https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/

  • Every list item has at least one paragraph of content, which may be wrapped, even using a hanging indent.

    Additional paragraphs or blocks are adjoined by putting a list continuation on a line adjacent to both blocks.

    list continuation

    a plus sign (+) on a line by itself

  • A literal paragraph does not require a list continuation.

    $ gem install asciidoctor
  • AsciiDoc lists may contain any complex content.

    Application Language

    AsciiDoc

    Python

    Asciidoctor

    Ruby

12.1. Java Functional Interfaces

Supplier       ()    -> x
Consumer       x     -> ()
Callable       ()    -> x throws ex
Runnable       ()    -> ()
Function       x     -> y
BiFunction     x,y   -> z
Predicate      x     -> boolean
UnaryOperator  x1    -> x2
BinaryOperator x1,x2 -> x3