yijuanmao opened a new issue, #37300:
URL: https://github.com/apache/shardingsphere/issues/37300

   In a custom sharding algorithm, the specified bean object cannot be obtained 
through springUtil, Caused by: java.lang.NullPointerException: null
   
   <properties>
           <fenmi.version>1.0.0</fenmi.version>
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
           
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
           <java.version>1.8</java.version>
           <sharding-jdbc.version>4.1.1</sharding-jdbc.version>
       </properties>
   
     <dependencies>  
   
           <dependency>
                   <groupId>org.apache.shardingsphere</groupId>
                   <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
                   <version>${sharding-jdbc.version}</version>
               </dependency>
   
          <!-- SpringBoot的依赖配置-->
               <dependency>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-dependencies</artifactId>
                   <version>2.2.13.RELEASE</version>
                   <type>pom</type>
                   <scope>import</scope>
               </dependency>
   
   </dependencies>
   
   
   ### Cause: java.lang.NullPointerException
        at 
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at 
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
        at 
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
        at sun.reflect.GeneratedMethodAccessor80.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
        ... 136 common frames omitted
   Caused by: java.lang.NullPointerException: null
        at com.rtx.common.utils.spring.SpringUtils.getBean(SpringUtils.java:64)
        at 
com.rtx.framework.config.shardingjdbc.DateRangeShardingAlgorithm.doSharding(DateRangeShardingAlgorithm.java:36)
        at 
org.apache.shardingsphere.core.strategy.route.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:78)
        at 
org.apache.shardingsphere.core.strategy.route.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:59)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeTables(ShardingStandardRoutingEngine.java:214)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route0(ShardingStandardRoutingEngine.java:195)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditionsWithCondition(ShardingStandardRoutingEngine.java:121)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditions(ShardingStandardRoutingEngine.java:115)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.getDataNodes(ShardingStandardRoutingEngine.java:96)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route(ShardingStandardRoutingEngine.java:74)
        at 
org.apache.shardingsphere.sharding.route.engine.ShardingRouteDecorator.decorate(ShardingRouteDecorator.java:69)
        at 
org.apache.shardingsphere.sharding.route.engine.ShardingRouteDecorator.decorate(ShardingRouteDecorator.java:53)
        at 
org.apache.shardingsphere.underlying.route.DataNodeRouter.executeRoute(DataNodeRouter.java:91)
        at 
org.apache.shardingsphere.underlying.route.DataNodeRouter.route(DataNodeRouter.java:76)
        at 
org.apache.shardingsphere.underlying.pluggble.prepare.PreparedQueryPrepareEngine.route(PreparedQueryPrepareEngine.java:54)
        at 
org.apache.shardingsphere.underlying.pluggble.prepare.BasePrepareEngine.executeRoute(BasePrepareEngine.java:96)
        at 
org.apache.shardingsphere.underlying.pluggble.prepare.BasePrepareEngine.prepare(BasePrepareEngine.java:83)
        at 
org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.prepare(ShardingPreparedStatement.java:183)
        at 
org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:143)
        at 
org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
        at 
org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
        at sun.reflect.GeneratedMethodAccessor83.invoke(Unknown Source)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
        at com.sun.proxy.$Proxy198.query(Unknown Source)
        at 
org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
        at 
org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
        at 
org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
        at 
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81)
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
        at com.sun.proxy.$Proxy197.query(Unknown Source)
        at 
com.github.pagehelper.util.ExecutorUtil.executeAutoCount(ExecutorUtil.java:166)
        at com.github.pagehelper.PageInterceptor.count(PageInterceptor.java:157)
        at 
com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:100)
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
        at com.sun.proxy.$Proxy197.query(Unknown Source)
        at 
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
        ... 141 common frames omitted
   
   
   @Component
   public final class SpringUtils implements BeanFactoryPostProcessor, 
ApplicationEventPublisherAware
           , ApplicationContextAware {
       /**
        * Spring应用上下文环境
        */
       private static ConfigurableListableBeanFactory beanFactory;
   
       private static ApplicationContext applicationContext;
   
       private static ApplicationEventPublisher publisher;
   
       @Override
       public void postProcessBeanFactory(ConfigurableListableBeanFactory 
beanFactory) throws BeansException {
           SpringUtils.beanFactory = beanFactory;
       }
   
       @Override
       public void setApplicationContext(ApplicationContext applicationContext) 
throws BeansException {
           SpringUtils.applicationContext = applicationContext;
       }
   
       /**
        * 获取对象
        *
        * @param name
        * @return Object 一个以所给名字注册的bean的实例
        * @throws org.springframework.beans.BeansException
        */
       @SuppressWarnings("unchecked")
       public static <T> T getBean(String name) throws BeansException {
           return (T) beanFactory.getBean(name);
       }
   
       /**
        * 获取类型为requiredType的对象
        *
        * @param clz
        * @return
        * @throws org.springframework.beans.BeansException
        */
       public static <T> T getBean(Class<T> clz) throws BeansException {
           T result = (T) beanFactory.getBean(clz);
           return result;
       }
   }
     
   
   <img width="1489" height="899" alt="Image" 
src="https://github.com/user-attachments/assets/0555a680-3771-4163-a9a3-7bdf9492d674";
 />
   
   <img width="1249" height="801" alt="Image" 
src="https://github.com/user-attachments/assets/fe8f3f66-8779-4a02-a063-785c6f1424bc";
 />
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to