Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Alternatively, you can add the dependencies manually in your `pom.xml` file:
Next, create a **User** model class that maps to a database table.

```java
package com.example.demo.model;
package in.newdevpoint.demo.model;

import javax.persistence.*;

Expand Down Expand Up @@ -109,9 +109,9 @@ public class User {
Create a **UserRepository** interface that extends `JpaRepository`, which provides built-in methods for CRUD operations.

```java
package com.example.demo.repository;
package in.newdevpoint.demo.repository;

import com.example.demo.model.User;
import in.newdevpoint.demo.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -125,10 +125,10 @@ public interface UserRepository extends JpaRepository<User, Long> {
Create a **UserService** class to handle the business logic.

```java
package com.example.demo.service;
package in.newdevpoint.demo.service;

import com.example.demo.model.User;
import com.example.demo.repository.UserRepository;
import in.newdevpoint.demo.model.User;
import in.newdevpoint.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -172,10 +172,10 @@ public class UserService {
Now, create a **UserController** to handle the API requests.

```java
package com.example.demo.controller;
package in.newdevpoint.demo.controller;

import com.example.demo.model.User;
import com.example.demo.service.UserService;
import in.newdevpoint.demo.model.User;
import in.newdevpoint.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -268,7 +268,7 @@ The H2 console will be accessible at `http://localhost:8080/h2-console`. You can
Once you have created the controller, service, and repository, you can run the Spring Boot application by executing the `main` method in your `SpringBootApplication` class.

```java
package com.example.demo;
package in.newdevpoint.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ To implement **JWT token-based authentication** in **Spring Boot** with **MongoD
Create a `User` model representing the user information to be stored in MongoDB.

```java
package com.example.demo.model;
package in.newdevpoint.demo.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
Expand Down Expand Up @@ -97,9 +97,9 @@ public class User {
We will create a MongoDB repository to manage user data:

```java
package com.example.demo.repository;
package in.newdevpoint.demo.repository;

import com.example.demo.model.User;
import in.newdevpoint.demo.model.User;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -116,7 +116,7 @@ public interface UserRepository extends MongoRepository<User, String> {
This class will be responsible for generating and validating JWT tokens.

```java
package com.example.demo.util;
package in.newdevpoint.demo.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
Expand Down Expand Up @@ -172,9 +172,9 @@ public class JwtUtil {
This filter will intercept incoming HTTP requests and check the `Authorization` header for a JWT token. It will validate the token and set the authentication context.

```java
package com.example.demo.filter;
package in.newdevpoint.demo.filter;

import com.example.demo.util.JwtUtil;
import in.newdevpoint.demo.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down Expand Up @@ -228,9 +228,9 @@ public class JwtRequestFilter extends OncePerRequestFilter {
Configure **Spring Security** to allow JWT-based authentication.

```java
package com.example.demo.config;
package in.newdevpoint.demo.config;

import com.example.demo.filter.JwtRequestFilter;
import in.newdevpoint.demo.filter.JwtRequestFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -270,11 +270,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
This controller handles user registration and login requests.

```java
package com.example.demo.controller;
package in.newdevpoint.demo.controller;

import com.example.demo.model.User;
import com.example.demo.repository.UserRepository;
import com.example.demo.util.JwtUtil;
import in.newdevpoint.demo.model.User;
import in.newdevpoint.demo.repository.UserRepository;
import in.newdevpoint.demo.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import org.springframework.stereotype.Component;
@Component
public class LoggingAspect {

@Around("execution(* com.example.service.*.*(..))") // Pointcut expression
@Around("execution(* in.newdevpoint.service.*.*(..))") // Pointcut expression
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long startTime = System.currentTimeMillis();

Expand All @@ -73,13 +73,13 @@ public class LoggingAspect {
- `@Aspect`: Marks the class as an aspect.
- `@Around`: Defines an **Around advice**, which wraps the target method.
- The `logExecutionTime` method captures the start time before method execution and calculates the execution time after the method completes.
- The pointcut expression `execution(* com.example.service.*.*(..))` means that this advice applies to all methods in the `com.example.service` package.
- The pointcut expression `execution(* in.newdevpoint.service.*.*(..))` means that this advice applies to all methods in the `in.newdevpoint.service` package.

#### Step 3: Service Class (Target Class)
Now, let’s define a simple service class where the logging aspect will be applied:

```java
package com.example.service;
package in.newdevpoint.service;

import org.springframework.stereotype.Service;

Expand All @@ -97,9 +97,9 @@ public class MyService {
Lastly, your Spring Boot application will automatically apply the aspect to the service methods. You can call the service from your main application class to see the AOP in action:

```java
package com.example;
package in.newdevpoint;

import com.example.service.MyService;
import in.newdevpoint.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
Expand Down Expand Up @@ -131,7 +131,7 @@ When you run the application, the method `performTask()` will execute and the as
1. **Before Advice**:
- Executes before the target method is called.
```java
@Before("execution(* com.example.service.MyService.performTask(..))")
@Before("execution(* in.newdevpoint.service.MyService.performTask(..))")
public void logBeforeMethod() {
System.out.println("Before method execution");
}
Expand All @@ -140,7 +140,7 @@ When you run the application, the method `performTask()` will execute and the as
2. **After Advice**:
- Executes after the target method completes, whether it succeeds or fails.
```java
@After("execution(* com.example.service.MyService.performTask(..))")
@After("execution(* in.newdevpoint.service.MyService.performTask(..))")
public void logAfterMethod() {
System.out.println("After method execution");
}
Expand All @@ -149,7 +149,7 @@ When you run the application, the method `performTask()` will execute and the as
3. **After Returning Advice**:
- Executes after the method successfully returns a value.
```java
@AfterReturning("execution(* com.example.service.MyService.performTask(..))")
@AfterReturning("execution(* in.newdevpoint.service.MyService.performTask(..))")
public void logAfterReturning() {
System.out.println("After method returns successfully");
}
Expand All @@ -158,7 +158,7 @@ When you run the application, the method `performTask()` will execute and the as
4. **After Throwing Advice**:
- Executes if the target method throws an exception.
```java
@AfterThrowing("execution(* com.example.service.MyService.performTask(..))")
@AfterThrowing("execution(* in.newdevpoint.service.MyService.performTask(..))")
public void logAfterThrowing() {
System.out.println("Exception thrown by the method");
}
Expand All @@ -167,7 +167,7 @@ When you run the application, the method `performTask()` will execute and the as
5. **Around Advice**:
- Wraps the method execution, allowing code to run before and after the method is executed.
```java
@Around("execution(* com.example.service.MyService.performTask(..))")
@Around("execution(* in.newdevpoint.service.MyService.performTask(..))")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Before method execution");
Object result = joinPoint.proceed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ You can dynamically view or change the logging levels of your application via th

```bash
curl -X POST -d '{"configuredLevel": "DEBUG"}' \
-H "Content-Type: application/json" http://localhost:8080/actuator/loggers/com.example
-H "Content-Type: application/json" http://localhost:8080/actuator/loggers/in.newdevpoint
```

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ This XML file contains Hibernate-specific configurations like database connectio
<property name="hibernate.hbm2ddl.auto">update</property>

<!-- Mapped classes -->
<mapping class="com.example.models.User"/>
<mapping class="in.newdevpoint.models.User"/>
</session-factory>
</hibernate-configuration>
```
Expand Down
8 changes: 4 additions & 4 deletions spring-boot-bootcamp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<groupId>in.newdevpoint</groupId>
<artifactId>spring-boot-bootcamp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-bootcamp</name>
Expand Down Expand Up @@ -197,9 +197,9 @@
<sourceFolder>src/main/java</sourceFolder>
<interfaceOnly>true</interfaceOnly>
</configOptions>
<packageName>com.example.bootcamp</packageName>
<apiPackage>com.example.bootcamp.api</apiPackage>
<modelPackage>com.example.bootcamp.dto</modelPackage>
<packageName>in.newdevpoint.bootcamp</packageName>
<apiPackage>in.newdevpoint.bootcamp.api</apiPackage>
<modelPackage>in.newdevpoint.bootcamp.dto</modelPackage>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.bootcamp;
package in.newdevpoint.bootcamp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.bootcamp.aop;
package in.newdevpoint.bootcamp.aop;

import com.example.bootcamp.repository.ExceptionLogRepository;
import in.newdevpoint.bootcamp.repository.ExceptionLogRepository;
import lombok.AllArgsConstructor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
Expand All @@ -13,7 +13,7 @@ public class LoggingAspect {

private final ExceptionLogRepository exceptionLogRepository;

@Around("execution(* com.example.bootcamp.controller.*.*(..))") // Pointcut expression
@Around("execution(* in.newdevpoint.bootcamp.controller.*.*(..))") // Pointcut expression
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long startTime = System.currentTimeMillis();

Expand All @@ -26,17 +26,17 @@ public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
return proceed;
}

@Before("execution(* com.example.bootcamp.service.UserService.*(..))") // Pointcut expression
@Before("execution(* in.newdevpoint.bootcamp.service.UserService.*(..))") // Pointcut expression
public void logBeforeMethod() {
System.out.println("Before method execution");
}

@After("execution(* com.example.bootcamp.service.UserService.*(..))")
@After("execution(* in.newdevpoint.bootcamp.service.UserService.*(..))")
public void logAfterMethod() {
System.out.println("After method execution");
}

/*@AfterThrowing(pointcut = "execution(* com.example.bootcamp..*(..))", throwing = "exception")
/*@AfterThrowing(pointcut = "execution(* in.newdevpoint.bootcamp..*(..))", throwing = "exception")
public void logException(JoinPoint joinPoint, Throwable exception) {
exception.printStackTrace();
ExceptionLog log = new ExceptionLog();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.bootcamp.config;
package in.newdevpoint.bootcamp.config;

import com.mongodb.client.MongoClient;
import javax.annotation.PreDestroy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.bootcamp.config;
package in.newdevpoint.bootcamp.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.bootcamp.config;
package in.newdevpoint.bootcamp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.bootcamp.config;
package in.newdevpoint.bootcamp.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.models.Components;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.bootcamp.controller;
package in.newdevpoint.bootcamp.controller;

import com.example.bootcamp.utility.BigONotation;
import in.newdevpoint.bootcamp.utility.BigONotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.example.bootcamp.controller;

import com.example.bootcamp.entity.ERole;
import com.example.bootcamp.entity.Role;
import com.example.bootcamp.entity.UserEntity;
import com.example.bootcamp.payload.request.LoginRequest;
import com.example.bootcamp.payload.request.SignupRequest;
import com.example.bootcamp.payload.response.JwtResponse;
import com.example.bootcamp.payload.response.MessageResponse;
import com.example.bootcamp.repository.RoleRepository;
import com.example.bootcamp.repository.UserRepository;
import com.example.bootcamp.security.jwt.JwtUtils;
import com.example.bootcamp.security.services.UserDetailsImpl;
package in.newdevpoint.bootcamp.controller;

import in.newdevpoint.bootcamp.entity.ERole;
import in.newdevpoint.bootcamp.entity.Role;
import in.newdevpoint.bootcamp.entity.UserEntity;
import in.newdevpoint.bootcamp.payload.request.LoginRequest;
import in.newdevpoint.bootcamp.payload.request.SignupRequest;
import in.newdevpoint.bootcamp.payload.response.JwtResponse;
import in.newdevpoint.bootcamp.payload.response.MessageResponse;
import in.newdevpoint.bootcamp.repository.RoleRepository;
import in.newdevpoint.bootcamp.repository.UserRepository;
import in.newdevpoint.bootcamp.security.jwt.JwtUtils;
import in.newdevpoint.bootcamp.security.services.UserDetailsImpl;
import jakarta.validation.Valid;
import java.util.Arrays;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.bootcamp.controller;
package in.newdevpoint.bootcamp.controller;

import com.example.bootcamp.data.SampleData;
import com.example.bootcamp.usecase.OrderService;
import com.example.bootcamp.usecase.SystemService;
import in.newdevpoint.bootcamp.data.SampleData;
import in.newdevpoint.bootcamp.usecase.OrderService;
import in.newdevpoint.bootcamp.usecase.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.example.bootcamp.controller;
package in.newdevpoint.bootcamp.controller;

import com.example.bootcamp.api.UsersApi;
import com.example.bootcamp.dto.UserReq;
import com.example.bootcamp.usecase.UserUseCase;
import com.example.bootcamp.utility.RoleConstants;
import in.newdevpoint.bootcamp.api.UsersApi;
import in.newdevpoint.bootcamp.dto.UserReq;
import in.newdevpoint.bootcamp.usecase.UserUseCase;
import in.newdevpoint.bootcamp.utility.RoleConstants;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.bootcamp.data;
package in.newdevpoint.bootcamp.data;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.bootcamp.entity;
package in.newdevpoint.bootcamp.entity;

import java.util.ArrayList;
import lombok.Data;
Expand Down
Loading