{"id":1138,"date":"2023-12-24T13:29:02","date_gmt":"2023-12-24T12:29:02","guid":{"rendered":"https:\/\/r-raimann.de\/WordPress\/?p=1138"},"modified":"2024-05-26T11:25:36","modified_gmt":"2024-05-26T10:25:36","slug":"back-end-using-spring-boot","status":"publish","type":"post","link":"https:\/\/r-raimann.de\/WordPress\/back-end-using-spring-boot\/","title":{"rendered":"Back-end using Spring Boot"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A java based framework to generate web application back end services<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Initialize a service<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Get started using spring initializr.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/start.spring.io\">https:\/\/start.spring.io<\/a><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Package Manager: Maven\nLanguage: Java\nSpring boot version: 2.5.3\nName &lt;test service>\nDependencies:\n- Spring Web\n- Spring Data JPA \n- PostgreSQL Driver <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Generate and unpack download file to project location<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open project in IDE (e.g. IntelliJ)<br>Run<br>Check in browser<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>localhost:8080<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add &#8220;hello world controller&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add package \"controller\"\nadd class \"InfoController\"<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>@RestController\npublic class InfoController  {\n     @GetMapping(\"\/\")\n     public String home() {\n        return \"This is the backend service for the application Homelab-Docu\";\n     }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Extend InfoController with version information<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    @Value(\"${app.name}\")\n    private String appName;\n\n    @Value(\"${app.description}\")\n    private String appDescription;\n\n    @Value(\"${app.version}\")\n    private String appVersion;\n\n    @GetMapping(\"\/version\")\n    public Object getVersion(HttpServletResponse response){\n        Map&lt;String, String> properties = new HashMap&lt;>();\n        properties.put(\"appName\", appName);\n        properties.put(\"appDescription\", appDescription);\n        properties.put(\"appVersion\", appVersion);\n\n        response.addHeader(\"Access-Control-Allow-Origin\", \"*\");\n        response.setStatus(HttpStatus.OK.value());\n\n        return properties;\n    }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A java based framework to generate web application back end services Initialize a service Get started using spring initializr. Generate<\/p>\n","protected":false},"author":1,"featured_media":1139,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[37,233],"tags":[251,250,252,248,249],"class_list":["post-1138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-latest","category-web-backend","tag-back-end","tag-boot","tag-java","tag-spring","tag-spring-boot"],"_links":{"self":[{"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/posts\/1138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/comments?post=1138"}],"version-history":[{"count":2,"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/posts\/1138\/revisions"}],"predecessor-version":[{"id":1206,"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/posts\/1138\/revisions\/1206"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/media\/1139"}],"wp:attachment":[{"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/media?parent=1138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/categories?post=1138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/r-raimann.de\/WordPress\/wp-json\/wp\/v2\/tags?post=1138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}