Skip to content

Instantly share code, notes, and snippets.

View vivekPandeyDev's full-sized avatar
🏠
Working from home

vivek pandey vivekPandeyDev

🏠
Working from home
  • Nucleus Software Exports
  • Noida
View GitHub Profile
@vivekPandeyDev
vivekPandeyDev / ValidDate.java
Last active January 20, 2024 13:49
create custom validation constraint
import com.vivek.managment.validator.ValidDateValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({FIELD, PARAMETER})
@vivekPandeyDev
vivekPandeyDev / CustomFormatter.java
Created January 20, 2024 13:58
Add custom formatter which format date to yyyy-MM-dd
/*
* Formatter helps parse the string to convert in java object and vice-versa
* Formatters in Spring are used for formatting fields when displaying them in views or when binding request parameters.
*/
// create a configuration and implement WebWvcConfigurer and overrid addFormatter
// create -> new LocalDateFormatter()
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class AppConfiguration implements WebMvcConfigurer {
@vivekPandeyDev
vivekPandeyDev / ArticleEndpoint.java
Created January 20, 2024 14:10
web service in spring boot
@Endpoint
public class ArticleEndpoint {
private static final String NAMESPACE_URI = "http://www.concretepage.com/article-ws";
@Autowired
private IArticleService articleService;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getArticleByIdRequest")
@ResponsePayload
public GetArticleByIdResponse getArticle(@RequestPayload GetArticleByIdRequest request) {
GetArticleByIdResponse response = new GetArticleByIdResponse();
@vivekPandeyDev
vivekPandeyDev / log4j2.xml
Created January 20, 2024 14:13
log4j in spring boot
/*
* add logging.config=classpath:log4j2.xml to properties file
*/
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="filename">./src/main/logs</Property>
</Properties>
<Appenders>
<RollingFile name="file" fileName="${filename}/my-logs.log" filePattern="${filename}/my-logs-%d{HH-mm-ss-SSS}.log">
@vivekPandeyDev
vivekPandeyDev / AppConfiguration.java
Last active January 20, 2024 14:22
WebMvcConfig for spring
@Configuration
@EnableWebMvc
@ComponentScan("com.spring")
@PropertySource("classpath:dbconfig.properties")
public class AppConfiguration implements WebMvcConfigurer {
@Autowired
private Environment env;
// front page location
@vivekPandeyDev
vivekPandeyDev / LoggerFilter.java
Last active January 20, 2024 14:25
spring security config for (!spring boot)
public class LoggerFilter extends OncePerRequestFilter {
private static final Logger log = LogManager.getLogger(LoggerFilter.class);
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
@vivekPandeyDev
vivekPandeyDev / ServerInitalization.java
Created January 20, 2024 14:26
spring bootstrap config
public class ServerInitalization extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] {SpringConfiguration.class};
@vivekPandeyDev
vivekPandeyDev / JwtAuthenticationFilter.java
Created January 20, 2024 15:29
jwt authentication spring
@Component
@RequiredArgsConstructor
public class JwtAuthenticationFilter extends OncePerRequestFilter {
private final JwtService jwtService;
private final UserDetailsService userInfoDetailService;
private final TokenRepository tokenRepository;
@Override
@vivekPandeyDev
vivekPandeyDev / CustomerController.java
Created January 20, 2024 15:53
property editor spring boot
package controller;
import config.BeanConfiguration;
import dto.CustomerDto;
import dto.EmiDto;
import entity.Customer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@vivekPandeyDev
vivekPandeyDev / Docker
Created January 21, 2024 13:32
docker compose
FROM maven:3.8.5-openjdk-17 AS build
COPY . .
RUN mvn clean package -DskipTests
FROM openjdk:17.0.1-jdk-slim
COPY --from=build /target/managment-0.0.1-SNAPSHOT.jar demo.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","demo.jar"]