<?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: Javed Khan</title>
    <description>The latest articles on DEV Community by Javed Khan (@javedkhan).</description>
    <link>https://dev.to/javedkhan</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%2F919778%2Fca97c755-1227-4ef5-8cb1-713fa7554b39.jpeg</url>
      <title>DEV Community: Javed Khan</title>
      <link>https://dev.to/javedkhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/javedkhan"/>
    <language>en</language>
    <item>
      <title>Springing Forward: A Smooth Transition to Spring Boot 3</title>
      <dc:creator>Javed Khan</dc:creator>
      <pubDate>Mon, 11 Mar 2024 15:43:16 +0000</pubDate>
      <link>https://dev.to/javedkhan/springing-forward-a-smooth-transition-to-spring-boot-3-214h</link>
      <guid>https://dev.to/javedkhan/springing-forward-a-smooth-transition-to-spring-boot-3-214h</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this article, we will delve into the essential steps and challenges involved in upgrading an existing application from Spring Boot 2 and Java 8 to Java 17 and Spring Boot 3. We will explore the solutions we implemented to overcome these issues, offering insights into potential stumbling blocks that may arise during your migration process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: JDK 17 Installation
&lt;/h2&gt;

&lt;p&gt;Begin the upgrade process by ensuring your system is equipped with Java Development Kit (JDK) 17. This version is the minimum requirement for Spring Boot 3 compatibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Gradle Upgrade
&lt;/h2&gt;

&lt;p&gt;Align your Gradle version with the prerequisites of Spring Boot 3. Upgrade to Gradle 7.5 or 8.x to optimize integration and performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Build Configuration Updates
&lt;/h2&gt;

&lt;p&gt;In your build.gradle file, update the build configuration to match the requirements of Spring Boot 3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;id 'org.springframework.boot' version '3.1.7'
id 'io.spring.dependency-management' version '1.1.4'

sourceCompatibility = '17'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Overcoming Challenges
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Package Name Changes from ‘javax’ to ‘jakarta’&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spring Boot 3 has embraced Jakarta EE, necessitating updates to package names. Here are the key changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;javax.persistence.* → jakarta.persistence.*
javax.validation.* → jakarta.validation.*
javax.servlet.* → jakarta.servlet.*
javax.annotation.* → jakarta.annotation.*
javax.transaction.* → jakarta.transaction.*
java.mail.* → jakarta.mail.*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: Packages like javax.sql.* and javax.crypto.* remain unchanged, as they are part of Java 17 JDK.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Handling Spring Security&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Spring Security version 5.7.0-M2, the WebSecurityConfigurerAdapter class underwent changes. Deprecated elements like authorizeRequests() and antMatchers() were replaced with authorizeHttpRequests() and requestMatchers().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {

    http
        .csrf()
        .disable()
        .authorizeHttpRequests()
        .requestMatchers("/api/v1/auth/**")
        .permitAll()
        .anyRequest()
        .authenticated()
        .and()
        .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .authenticationProvider(authenticationProvider)
        .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);

    return http.build();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refer to Spring Security Documentation for more details.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Mail Service Dependency Update&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Replace the deprecated javax.mail dependency with the Spring Boot provided dependency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;implementation 'org.springframework.boot:spring-boot-starter-mail'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;JPA Specification and Database Query&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Address the generic error involving JPA Specification with a solution provided in this Stack Overflow thread.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Handling Duplicate Key Errors&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If encountering duplicate key errors after calling an API, adjust your entity class annotations from @GeneratedValue(strategy = GenerationStrategy.AUTO) to @GeneratedValue(strategy = GenerationType.SEQUENCE) and include @SequenceGenerator for each entity.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hibernate 6.0 now creates a sequence per entity hierarchy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Deprecated Hibernate Annotation&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If using @Type(type = “org.hibernate.type.PostgresUUIDType”), remove it as it is no longer required in Hibernate 6.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Navigating the upgrade to Spring Boot 3 might present challenges, yet addressing these issues ensures that your application remains up-to-date and takes full advantage of the latest features. Sharing our experiences fosters a collective understanding of potential hurdles in the migration process. We encourage you to share your challenges and solutions in the comments section below.&lt;/p&gt;

</description>
      <category>spring</category>
      <category>springboot</category>
      <category>java17</category>
      <category>springboot3</category>
    </item>
    <item>
      <title>Comprehensive Guide to OpenAPI Swagger Integration in Spring Boot with Spring Security JWT</title>
      <dc:creator>Javed Khan</dc:creator>
      <pubDate>Sun, 03 Dec 2023 11:09:29 +0000</pubDate>
      <link>https://dev.to/javedkhan/comprehensive-guide-to-openapi-swagger-integration-in-spring-boot-with-spring-security-jwt-2hb</link>
      <guid>https://dev.to/javedkhan/comprehensive-guide-to-openapi-swagger-integration-in-spring-boot-with-spring-security-jwt-2hb</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tpdiea013jfoncmaenx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tpdiea013jfoncmaenx.png" alt="OpenAPI | Swagger | Spring Boot" width="387" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;This comprehensive guide walks you through the process of integrating OpenAPI Swagger with a Spring Boot 3 project, while seamlessly incorporating Spring Security JWT for enhanced security. OpenAPI Swagger serves as a powerful tool for API documentation, aiding developers in understanding, testing, and interacting with your API effortlessly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is OpenAPI Swagger?
&lt;/h2&gt;

&lt;p&gt;OpenAPI Swagger is an industry-standard specification for building APIs. It provides a language-agnostic interface to describe the functionality of your RESTful services. Swagger tools allow developers to generate interactive documentation, client SDKs, and even server stubs based on your API specifications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Interactive Documentation: Swagger UI provides an interactive and user-friendly interface, allowing developers to explore and test API endpoints in real-time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code Generation: Generate client libraries and server stubs in various programming languages directly from your API specifications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consistency: Ensure consistency and alignment between API design and implementation by maintaining a single source of truth.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step-by-Step Guide:
&lt;/h2&gt;

&lt;p&gt;Step 1: Add the springdoc-openapi Dependency&lt;/p&gt;

&lt;p&gt;Include the springdoc-openapi library in your project’s dependencies to enable seamless integration with Spring Boot.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step 2: Create OpenApiConfig Class&lt;/p&gt;

&lt;p&gt;Create a configuration class (SwaggerConfig) to customize OpenAPI documentation and handle Spring Security JWT. Here we are implementing using java.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Configuration
public class SwaggerConfig {
String schemeName = "bearerAuth";
String bearerFormat = "JWT";
String scheme = "bearer";
@Bean
public OpenAPI caseOpenAPI() {
        return new OpenAPI()
                  .addSecurityItem(new SecurityRequirement()
.addList(schemeName)).components(new Components()
                                  .addSecuritySchemes(
                                        schemeName, new SecurityScheme()
                                        .name(schemeName)
                                        .type(SecurityScheme.Type.HTTP)
                                        .bearerFormat(bearerFormat)
                                        .in(SecurityScheme.In.HEADER)
                                        .scheme(scheme)
                                  )
                  )
                  .info(new Info()
                              .title("Case Management Service")
                              .description("Claim Event Information")
                              .version("1.0")
                  );
        }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also implement the config using annotations provided by swagger.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@OpenAPIDefinition(
        info = @Info(
                title = "Claims Service",
                version = "1.0",
                description = "Claims Information"
        ),
        security = {
                @SecurityRequirement(name = "bearerAuth")
        }
)
@SecurityScheme(
        name = "bearerAuth",
        description = "JWT authentication",
        scheme = "bearer",
        type = SecuritySchemeType.HTTP,
        bearerFormat = "JWT",
        in = SecuritySchemeIn.HEADER
)
public class SwaggerConfig {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Configure Swagger UI Optionally, customize the path to Swagger UI in your application.properties or application.yml file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;springdoc.swagger-ui.path=/custom/swagger-ui&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step 4: Configure Spring Security to Ignore Swagger UI URLs&lt;br&gt;
Exclude specific URLs from Spring Security to allow public access to Swagger UI and API documentation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ... existing security configurations

@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
    return web -&amp;gt; web.ignoring().requestMatchers(
            "/swagger-ui/**", "/v3/api-docs/**"
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this update, the specified URLs (“/swagger-ui/” and “/v3/api-docs/”) will be ignored by Spring Security, allowing public access to the Swagger UI and API documentation.&lt;/p&gt;

&lt;p&gt;Step 5: Run the Application&lt;/p&gt;

&lt;p&gt;Start your Spring Boot application and access the Swagger UI to explore and test your API.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://localhost:8080/custom/swagger-ui.html&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step 6: Explore API Documentation&lt;/p&gt;

&lt;p&gt;Utilize the power of Swagger UI to interactively explore API endpoints, request parameters, and responses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;By following these steps, we have successfully integrated OpenAPI Swagger with Spring Boot project, configured it to work with Spring Security JWT, and provided an interactive API documentation platform for development team.&lt;/p&gt;

</description>
      <category>springboot</category>
      <category>swagger</category>
      <category>openapi</category>
      <category>jwt</category>
    </item>
    <item>
      <title>Spring Boot Feature Flag</title>
      <dc:creator>Javed Khan</dc:creator>
      <pubDate>Sat, 03 Sep 2022 05:57:06 +0000</pubDate>
      <link>https://dev.to/javedkhan/spring-boot-feature-flag-3la3</link>
      <guid>https://dev.to/javedkhan/spring-boot-feature-flag-3la3</guid>
      <description>&lt;h2&gt;
  
  
  What is a feature flag?
&lt;/h2&gt;

&lt;p&gt;A feature flag is a software development process used to enable or disable functionality remotely without deploying code. New features can be deployed without making them visible to users. Feature flags help decouple deployment from release letting you manage the full lifecycle of a feature.&lt;/p&gt;

&lt;p&gt;Feature flags go by many names:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Feature toggle&lt;/li&gt;
&lt;li&gt;Feature flipper&lt;/li&gt;
&lt;li&gt;Conditional feature&lt;/li&gt;
&lt;li&gt;Feature switch&lt;/li&gt;
&lt;li&gt;Feature controls&lt;/li&gt;
&lt;li&gt;Release toggle&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Docker
&lt;/h2&gt;

&lt;p&gt;Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dockerfiles&lt;/strong&gt; are text documents that allow you to build images for Docker&lt;/p&gt;

&lt;p&gt;You will find the project &lt;a href="https://https://github.com/imjavedkhan/ConfigCatFeatureFlag"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Below command to build image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t spring-docker:latest .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Below command to run container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --name spd -d -p 8080:8080 spring-docker:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgg0wva3z3hwxjo5wvqte.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgg0wva3z3hwxjo5wvqte.png" alt="Screenshot" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>featureflag</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
