{"@attributes":{"version":"2.0"},"channel":{"title":"Spring on Kevin Sookocheff","link":"https:\/\/sookocheff.com\/tags\/spring\/","description":"Recent content in Spring on Kevin Sookocheff","generator":"Hugo","language":"en-us","lastBuildDate":"Wed, 19 May 2021 08:01:52 -0600","item":[{"title":"Augmenting Spring Data REST with Additional Endpoints","link":"https:\/\/sookocheff.com\/post\/java\/augmenting-spring-data-rest-with-additional-endpoints\/","pubDate":"Wed, 19 May 2021 08:01:52 -0600","guid":"https:\/\/sookocheff.com\/post\/java\/augmenting-spring-data-rest-with-additional-endpoints\/","description":"<p>Spring Data REST combines the features of <a href=\"https:\/\/spring.io\/projects\/spring-data\">Spring\nData<\/a> with <a href=\"https:\/\/spring.io\/projects\/spring-hateoas\">Spring\nHATEOAS<\/a> to make it easy to\nbuild hypermedia-driven REST APIs on top of Spring Data repositories. The\nbasic functionality provided out of the box creates and exposes simple\nREST endpoints for performing CRUD operations on Spring Data repositories.\nFor a lot of use cases, this is entirely enough functionality to meet your\nneeds. In other cases, you need to extend the REST API to include\nadditional functionality that isn\u2019t provided by Spring Data REST and it\ncan be difficult to determine exactly how to do this. In this blog post,\nI show you how to augment a Spring Data REST API with additional endpoints\nto turn a basic CRUD API into a full featured web service.<\/p>"},{"title":"Understanding Spring's Environment Abstraction","link":"https:\/\/sookocheff.com\/post\/java\/understanding-springs-environment-abstraction\/","pubDate":"Wed, 27 May 2020 09:57:12 -0600","guid":"https:\/\/sookocheff.com\/post\/java\/understanding-springs-environment-abstraction\/","description":"<p>When working with Spring Boot, some auto-configuration can happen seemingly by\nmagic. For example, in a traditional Spring application with Java-based\nconfiguration, you might configure an H2 database using the following block of\ncode to set the type of the database and run some scripts to initialize it:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"line\"><span class=\"cl\"><span class=\"nd\">@Bean<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"kd\">public<\/span><span class=\"w\"> <\/span><span class=\"n\">DataSource<\/span><span class=\"w\"> <\/span><span class=\"nf\">dataSource<\/span><span class=\"p\">()<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">    <\/span><span class=\"k\">return<\/span><span class=\"w\"> <\/span><span class=\"k\">new<\/span><span class=\"w\"> <\/span><span class=\"n\">EmbeddedDataSourceBuilder<\/span><span class=\"p\">()<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"p\">.<\/span><span class=\"na\">setType<\/span><span class=\"p\">(<\/span><span class=\"n\">H2<\/span><span class=\"p\">)<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"p\">.<\/span><span class=\"na\">addScript<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;taco_schema.sql&#34;<\/span><span class=\"p\">)<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"p\">.<\/span><span class=\"na\">addScripts<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;user_data.sql&#34;<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s\">&#34;ingredient_data.sql&#34;<\/span><span class=\"p\">)<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"w\">        <\/span><span class=\"p\">.<\/span><span class=\"na\">build<\/span><span class=\"p\">();<\/span><span class=\"w\">\n<\/span><\/span><\/span><span class=\"line\"><span class=\"cl\"><span class=\"p\">}<\/span><span class=\"w\">\n<\/span><\/span><\/span><\/code><\/pre><\/div><p>With Spring Boot, you can remove this entire block of code and use\nauto-configuration. If the H2 dependency is available in the classpath, Spring\nBoot will automatically create the <code>DataSource<\/code> and add it as a <code>Bean<\/code> to\nSpring&rsquo;s application context and apply SQL scripts as long as they are named\n<code>schema.sql<\/code> or <code>data.sql<\/code>. Spring Boot does this auth-configuration by\nleveraging the Spring environment that collects the set of properties available\nto a Java application and uses those properties to configure beans in Spring&rsquo;s\napplication context. The following figure from <a href=\"https:\/\/www.manning.com\/books\/spring-in-action-fifth-edition\">Spring in\nAction<\/a> shows how\nthe Spring environment is generated by some of the available configuration\nproperty sources available in a typical Java application.<\/p>"},{"title":"Building a Modern Java Web App with Spring Boot","link":"https:\/\/sookocheff.com\/post\/java\/building-a-modern-java-web-app-with-spring-boot\/","pubDate":"Wed, 20 May 2020 09:13:12 -0600","guid":"https:\/\/sookocheff.com\/post\/java\/building-a-modern-java-web-app-with-spring-boot\/","description":"<p>I&rsquo;m a <a href=\"https:\/\/sookocheff.com\/post\/java\/why-java\/\">fan of Java<\/a>. If you haven&rsquo;t\ngiven it a chance in a while, you may not have noticed that, Java has quietly\nbeen adopting some of the best practices that make dynamic and functional\nlanguages so appealing, without sacrificing the many hundred person-years of\neffort that have made Java and the JVM a world-class development environment.\nJava is still one the world\u2019s <a href=\"https:\/\/www.tiobe.com\/tiobe-index\/\">most popular programming\nlanguages<\/a> with roughly 9 million\nprogrammers using Java. It doesn\u2019t make sense to ignore all of that history and\ndevelopment effort because of a niggling feeling that Java is a little too\nverbose, or that XML is so last year.<\/p>"},{"title":"Inversion of Control, Dependency Injection, and the Spring IoC Container","link":"https:\/\/sookocheff.com\/post\/java\/inversion-of-control-and-the-spring-ioc-container\/","pubDate":"Thu, 14 May 2020 09:13:12 -0600","guid":"https:\/\/sookocheff.com\/post\/java\/inversion-of-control-and-the-spring-ioc-container\/","description":"<p>Inversion of Control (IoC), also known as Dependency Injection (DI), allows an\nobject to define their dependencies as constructor arguments (strictly speaking,\nyou can set these dependencies as properties, but the examples I will use today\nare constructor-based). This is the inverse of the object itself controlling the\ninstantiation or location of its dependencies, hence the name <em>Inversion of Control<\/em>.<\/p>\n<p>Let&rsquo;s look at an example from\n<a href=\"https:\/\/stackoverflow.com\/questions\/3058\/what-is-inversion-of-control\">Stackoverflow<\/a>\nusing a text editor with a spell checking component:<\/p>"}]}}