Skip to content

Commit

Permalink
📦 dependency: add dependecies #3
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jul 13, 2024
1 parent 33e02c9 commit be66a8f
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
12 changes: 12 additions & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ plugins {

// Apply the Groovy plugin to add support for Groovy
id 'groovy'

// Apply the Spring dependency management plugin for managing dependencies
id 'io.spring.dependency-management' version '1.1.4'
}

apply plugin: 'java'
Expand Down Expand Up @@ -160,4 +163,13 @@ dependencies {
implementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.9.0'
// The "validation-api" library, version 2.0.1.Final, provides tools for validating Java objects according to defined constraints.
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
// The "spring-core" library, version 5.3.31, is a fundamental component of the Spring Framework,
// offering essential functionality for dependency injection, bean management, and core utilities to facilitate robust Java application development within the Spring ecosystem.
implementation group: 'org.springframework', name: 'spring-core', version: '5.3.31'
// The "spring-boot-starter-web" library, version 2.7.18, is a Spring Boot starter module that facilitates the setup of web applications,
// providing essential dependencies and configurations for building web-based projects.
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.7.18'
// The "spring-boot-configuration-processor" library, version 2.7.18,
// is a Spring Boot module that processes configuration metadata annotations to generate metadata files and aid in auto-configuration of Spring applications.
implementation group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.7.18'
}
99 changes: 99 additions & 0 deletions plugin/src/main/groovy/org/redis4j/config/Redis4jBeanConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.redis4j.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
* Configures access to the Spring application context.
*/
@Component
public class Redis4jBeanConfig implements BeanFactoryPostProcessor {

private static ConfigurableListableBeanFactory beanFactory;

/**
* Retrieves the ConfigurableListableBeanFactory instance.
*
* @return the ConfigurableListableBeanFactory instance
*/
public static ConfigurableListableBeanFactory getBeanFactory() {
return beanFactory;
}

/**
* Retrieves a bean by name from the Spring application context.
*
* @param name the name of the bean to retrieve
* @param <T> the type of the bean
* @return the bean instance
* @throws BeansException if an error occurs while retrieving the bean
*/
@SuppressWarnings({"unchecked"})
public static <T> T getBean(String name) throws BeansException {
return (T) getBeanFactory().getBean(name);
}

/**
* Retrieves a bean by type from the Spring application context.
*
* @param clazz the class of the bean to retrieve
* @param <T> the type of the bean
* @return the bean instance
* @throws BeansException if an error occurs while retrieving the bean
*/
public static <T> T getBean(Class<T> clazz) throws BeansException {
return getBeanFactory().getBean(clazz);
}

/**
* Checks if a bean with the specified name exists in the Spring application context.
*
* @param name the name of the bean to check
* @return true if the bean exists, false otherwise
*/
public static boolean containsBean(String name) {
return getBeanFactory().containsBean(name);
}

/**
* Checks if the bean with the specified name is a singleton in the Spring application context.
*
* @param name the name of the bean to check
* @return true if the bean is a singleton, false otherwise
* @throws NoSuchBeanDefinitionException if the bean definition cannot be found
*/
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
return getBeanFactory().isSingleton(name);
}

/**
* Retrieves the type of the bean with the specified name from the Spring application context.
*
* @param name the name of the bean
* @return the type of the bean
* @throws NoSuchBeanDefinitionException if the bean definition cannot be found
*/
public static Class<?> getType(String name) throws NoSuchBeanDefinitionException {
return getBeanFactory().getType(name);
}

/**
* Retrieves the aliases for the bean with the specified name from the Spring application context.
*
* @param name the name of the bean
* @return an array of alias names
* @throws NoSuchBeanDefinitionException if the bean definition cannot be found
*/
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException {
return getBeanFactory().getAliases(name);
}

@SuppressWarnings({"NullableProblems"})
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
Redis4jBeanConfig.beanFactory = factory;
}
}

0 comments on commit be66a8f

Please sign in to comment.