<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Boufnichel</title>
    <description>The latest articles on DEV Community by Boufnichel (@boufnichel).</description>
    <link>https://dev.to/boufnichel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F864560%2F38d99cf0-72fa-4093-b42b-cdb0b72a058a.jpg</url>
      <title>DEV Community: Boufnichel</title>
      <link>https://dev.to/boufnichel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/boufnichel"/>
    <language>en</language>
    <item>
      <title>In computer science, we don't just fix problems. We make the magic that powers today's world.</title>
      <dc:creator>Boufnichel</dc:creator>
      <pubDate>Sat, 06 Jan 2024 20:32:24 +0000</pubDate>
      <link>https://dev.to/boufnichel/in-computer-science-we-dont-just-fix-problems-we-make-the-magic-that-powers-todays-world-38ei</link>
      <guid>https://dev.to/boufnichel/in-computer-science-we-dont-just-fix-problems-we-make-the-magic-that-powers-todays-world-38ei</guid>
      <description>&lt;p&gt;In computer science, we don't just fix problems. We make the magic that powers today's world.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Dockerizing a Spring Boot Application</title>
      <dc:creator>Boufnichel</dc:creator>
      <pubDate>Sun, 07 May 2023 20:09:31 +0000</pubDate>
      <link>https://dev.to/boufnichel/dockerizing-a-spring-boot-application-4eo6</link>
      <guid>https://dev.to/boufnichel/dockerizing-a-spring-boot-application-4eo6</guid>
      <description>&lt;p&gt;Why Dockerize a Spring Boot Application?&lt;br&gt;
When developing a Spring Boot application, we want it to run smoothly and efficiently in production. However, deploying an application to a production environment can be a challenging and time-consuming process. It requires us to set up a proper runtime environment, install all required dependencies, and ensure that everything is configured correctly.&lt;/p&gt;

&lt;p&gt;This is where Docker comes in handy. Docker is a powerful containerization platform that enables developers to package their applications along with all the necessary dependencies, libraries, and configurations into a single container. Dockerizing a Spring Boot application can simplify deployment and make it more efficient, consistent, and predictable across different environments.&lt;br&gt;
In this article, we will guide you through the process of dockerizing a Spring Boot application step by step. We assume that you have some basic knowledge of Spring Boot and Docker. Let's get started!&lt;br&gt;
&lt;strong&gt;Step 1:&lt;/strong&gt; Create a new Spring Boot application using the Spring Initializr. To do so, navigate to &lt;a href="https://start.spring.io"&gt;https://start.spring.io&lt;/a&gt; in your browser.&lt;br&gt;
&lt;strong&gt;Step 2:&lt;/strong&gt; Select the required project details, such as the project type, language, and dependencies. Click on the GENERATE button to download the project.&lt;br&gt;
&lt;strong&gt;Step 3:&lt;/strong&gt; Extract the downloaded ZIP file and import the project into your IDE.&lt;br&gt;
&lt;strong&gt;Step 4:&lt;/strong&gt; In the IDE, open the base Java file of the project and add a new simple controller to the base class of the application : &lt;br&gt;
&lt;code&gt;@RequestMapping("/")&lt;br&gt;
public String home() {&lt;br&gt;
    return "Dockerizing Spring Boot Application";&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Add the RestController annotation and import the required packages. In the end, you must have something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.docker.spring;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class Application {

    @RequestMapping("/")
    public String home() {
        return "Dockerizing Spring Boot Application";
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Start the application by running the following command in your terminal:&lt;br&gt;
&lt;code&gt;./mvnw spring-boot:run&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Navigate to &lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt; in your browser to test the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Create a new file called Dockerfile in the root directory of your Spring Boot project, and paste the following contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Fetching latest version of Java
FROM openjdk:18

# Setting up work directory
WORKDIR /app

# Copy the jar file into our app
COPY ./target/spring-0.0.1-SNAPSHOT.jar /app

# Exposing port 8080
EXPOSE 8080

# Starting the application
CMD ["java", "-jar", "spring-0.0.1-SNAPSHOT.jar"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; Build a new Docker image by running the following command in your terminal. Replace [name:tag] with a name and tag for the image:&lt;br&gt;
&lt;code&gt;docker build -t [name:tag] .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 10:&lt;/strong&gt; Once the build process is complete, you can start a new Docker container by running the following command:&lt;br&gt;
&lt;code&gt;docker run -p 8080:8080 [name:tag]&lt;/code&gt;&lt;br&gt;
The -p flag maps the exposed container port to a port on the host machine. In this case, we are mapping port 8080 of the container to port 8080 of the host machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 11:&lt;/strong&gt; Navigate to &lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt; in your browser to test the application running inside the Docker container.&lt;/p&gt;

&lt;p&gt;And congratulations! You have now Dockerized your Spring Boot application and deployed it inside a container. This makes it easy to deploy and run the application on different machines without worrying about dependencies and environment-specific configurations.&lt;/p&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>docker</category>
    </item>
    <item>
      <title>Building GraphQL APIs with Spring Boot</title>
      <dc:creator>Boufnichel</dc:creator>
      <pubDate>Sat, 11 Mar 2023 10:37:07 +0000</pubDate>
      <link>https://dev.to/boufnichel/building-graphql-apis-with-spring-boot-plp</link>
      <guid>https://dev.to/boufnichel/building-graphql-apis-with-spring-boot-plp</guid>
      <description>&lt;p&gt;GraphQL is an API standard that has been gaining popularity in recent years due to its flexibility and efficiency. It allows clients to specify exactly what data they need and in what format, which can reduce the amount of data sent over the wire and improve performance. In this article, we'll explore how to build GraphQL APIs with Spring Boot.&lt;/p&gt;

&lt;p&gt;Getting Started with GraphQL&lt;/p&gt;

&lt;p&gt;To get started with GraphQL, you need to define a schema that describes the types of data that your API can return. A schema consists of a set of types, each of which has one or more fields. Fields can be of different types, including scalars (like strings and integers), objects (defined by other types), and lists (of other types). Here's an example schema for a simple blog API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Query {
  posts: [Post]
}

type Post {
  id: ID!
  title: String!
  body: String!
  author: User!
}

type User {
  id: ID!
  name: String!
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This schema defines three types: Query, Post, and User. The Query type has one field, posts, which returns a list of Post objects. The Post type has four fields: id, title, body, and author. The author field is an object of type User. The User type has two fields: id and name.&lt;/p&gt;

&lt;p&gt;Building a GraphQL API with Spring Boot&lt;/p&gt;

&lt;p&gt;Now that we have a schema, let's build a GraphQL API with Spring Boot. We'll use the graphql-java library to parse and execute GraphQL queries.&lt;/p&gt;

&lt;p&gt;First, add the following dependencies to your build.gradle or pom.xml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies {
  implementation 'com.graphql-java:graphql-spring-boot-starter:15.0.0'
  implementation 'com.graphql-java:graphql-java-tools:15.0.2'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a GraphQL controller that handles GraphQL queries. Here's an example controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@RestController
@RequestMapping("/graphql")
public class GraphQLController {

  private final GraphQL graphQL;

  public GraphQLController(GraphQL graphQL) {
    this.graphQL = graphQL;
  }

  @PostMapping
  public ResponseEntity&amp;lt;Object&amp;gt; query(@RequestBody String query) {
    ExecutionResult result = graphQL.execute(query);
    return ResponseEntity.ok(result.getData());
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This controller maps HTTP POST requests to the /graphql endpoint and executes the GraphQL query passed in the request body. The result of the query is returned in the response.&lt;/p&gt;

&lt;p&gt;To create a GraphQL schema from our schema definition, we'll use the graphql-java-tools library. Add the following code to your main Spring Boot application class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@SpringBootApplication
public class MyApp {

  public static void main(String[] args) {
    SpringApplication.run(MyApp.class, args);
  }

  @Bean
  public GraphQLSchema schema() {
    TypeRegistry typeRegistry = new TypeRegistry();
    SchemaParser schemaParser = new SchemaParser();
    typeRegistry.merge(schemaParser.parse(
      "type Query { posts: [Post] }" +
      "type Post { id: ID!, title: String!, body: String!, author: User! }" +
      "type User { id: ID!, name: String! }"
    ));

    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
      .type("Query", builder -&amp;gt; builder.dataFetcher("posts", new PostsFetcher()))
      .type("Post", builder -&amp;gt; builder.dataFetcher("author", new AuthorFetcher()))
      .build();

    SchemaGenerator schemaGenerator = new SchemaGenerator();
    return schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Spring boot : A security without WebSecurityConfigurerAdapter</title>
      <dc:creator>Boufnichel</dc:creator>
      <pubDate>Fri, 27 Jan 2023 20:18:28 +0000</pubDate>
      <link>https://dev.to/boufnichel/spring-boot-a-security-without-websecurityconfigureradapter-2f07</link>
      <guid>https://dev.to/boufnichel/spring-boot-a-security-without-websecurityconfigureradapter-2f07</guid>
      <description>&lt;p&gt;Web security is an essential aspect of any web application, and it is crucial to keep it up-to-date with the latest best practices. One of the ways to secure a web application built with Spring is by using the &lt;strong&gt;WebSecurityConfigurerAdapter&lt;/strong&gt; class. This class has been a powerful tool for developers, as it allows for fine-grained control over the application's security settings. However, starting with Spring Security 5.0, the WebSecurityConfigurerAdapter class has been deprecated in favor of a new approach using the &lt;strong&gt;SecurityFilterChain&lt;/strong&gt; bean.&lt;/p&gt;

&lt;p&gt;The old way of configuring security using WebSecurityConfigurerAdapter is a quite verbose and can be confusing for some developers. Let's take a look at an example of how it would look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyjypwa7n0n37qdto6bj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyjypwa7n0n37qdto6bj.png" alt="Image description" width="800" height="601"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, we are defining two methods configure(AuthenticationManagerBuilder auth) and configure(HttpSecurity http). The first one is used to configure the authentication manager, and the second one is used to configure the authorization rules.&lt;/p&gt;

&lt;p&gt;We can see that the configure(AuthenticationManagerBuilder auth) method is used to set up the UserDetailsService and PasswordEncoder to be used by the authentication manager.&lt;/p&gt;

&lt;p&gt;The configure(HttpSecurity http) method is used to define the authorization rules. We can see that we are using antMatchers to match the requested URLs, and then we are using the hasRole method to define the role that is required to access those URLs.&lt;/p&gt;

&lt;p&gt;As you can see, the old approach is quite verbose, and it can be difficult to understand for some developers. However, starting with Spring Security 5.0, a new approach has been introduced to configure security. The new approach uses the SecurityFilterChain bean, and it is more concise and easier to understand. Let's take a look at an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj7d45j6g866nvkh2f81d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj7d45j6g866nvkh2f81d.png" alt="Image description" width="800" height="510"&gt;&lt;/a&gt;&lt;br&gt;
In this example, we are using the &lt;strong&gt;SecurityFilterChain&lt;/strong&gt; bean to configure security. The SecurityFilterChain bean is a functional bean that allows for more flexibility in terms of configuring security settings.&lt;br&gt;
So you only need to implement a single method, for whatever your embeded datasource, and make your config as we want.&lt;/p&gt;

</description>
      <category>gratitude</category>
      <category>website</category>
      <category>jokes</category>
    </item>
    <item>
      <title>Is Spring Boot worth considering over Spring? ?</title>
      <dc:creator>Boufnichel</dc:creator>
      <pubDate>Thu, 12 Jan 2023 12:15:01 +0000</pubDate>
      <link>https://dev.to/boufnichel/use-spring-boot-instead-of-spring--260f</link>
      <guid>https://dev.to/boufnichel/use-spring-boot-instead-of-spring--260f</guid>
      <description>&lt;p&gt;A feature of Spring Framework that allows managing application's objects dependencies, it's the dependency injection.&lt;/p&gt;

&lt;p&gt;But unlike Spring Framework, Spring Boot has no need of XML configuration (spring beans configuration..).&lt;/p&gt;

&lt;p&gt;For example, Why do you need to restart you server manually for every code changes and the starter-projects can make it with just one dependency ?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fchebgbovhmgx9j8ifbbl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fchebgbovhmgx9j8ifbbl.png" alt="Image description" width="700" height="275"&gt;&lt;/a&gt;&lt;br&gt;
Spring Boot is a powerful framework that allows developers to quickly create and run Spring-based applications with minimal configuration. It provides a number of features and conventions that make it easier to get started with a new project and to quickly build, test, and deploy your application.&lt;/p&gt;

&lt;p&gt;One of the key features of Spring Boot is its &lt;strong&gt;starter_projects&lt;/strong&gt;. Spring Boot provides a number of "starter POMs" that allow developers to quickly add common dependencies to their project(JPA, Devtools, Hibernate...). This can save a lot of time and effort when setting up a new project, as you don't need to manually add and configure all the dependencies. The starter POMs also ensure that you are using the correct versions of the dependencies, which can help to prevent compatibility issues.&lt;/p&gt;

&lt;p&gt;Another great feature of Spring Boot is its &lt;strong&gt;autoconfiguration&lt;/strong&gt;. It can automatically configure a lot of the settings and dependencies for your application, based on the libraries you have included in your project. This means that you don't need to spend lots of time configuring your application and can instead focus on writing the code that makes your application unique. The autoconfiguration feature can also help to prevent common configuration mistakes and make it easier to deploy your application to different environments.&lt;/p&gt;

&lt;p&gt;Another feature that makes Spring Boot better than Spring Framework is its #embedded_servers. You can run your application on an embedded server, such as &lt;strong&gt;Tomcat&lt;/strong&gt; or Jetty, without the need to set up and configure a separate server(you don't need to add any Library or .JAR files). This can save a lot of time and effort and also makes it easy to deploy your application to different environments.&lt;/p&gt;

&lt;p&gt;Finally, Spring Boot includes an #actuator that provides information about the health and performance of your application. This can be very useful for monitoring and troubleshooting your application and also allows you to perform operations such as shutting down the application. This can also help you to quickly identify and fix any problems with your application, which can help to ensure that your application is always running correctly.&lt;br&gt;
All of these features combined make Spring Boot a more opinionated and easy-to-use framework as compared to Spring Framework. It requires minimal configuration and provides many features out of the box, which makes it easy to create and run Spring-based applications. If you are looking to start a new project or to quickly develop and deploy a Spring-based application, then Spring Boot is definitely worth considering.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
