All about abstract classes.

部署运行你感兴趣的模型镜像

Introduction

Abstract classes are one of the essential behaviors provided by .NET. Commonly, you would like to make classes that only represent base classes, and don’t want anyone to create objects of these class types. You can make use of abstract classes to implement such functionality in C# using the modifier 'abstract'.

An abstract class means that, no object of this class can be instantiated, but can make derivations of this.

An example of an abstract class declaration is:

abstract class absClass
{
}

An abstract class can contain either abstract methods or non abstract methods. Abstract members do not have any implementation in the abstract class, but the same has to be provided in its derived class.

An example of an abstract method:

abstract class absClass
{
  public abstract void abstractMethod();
}

Also, note that an abstract class does not mean that it should contain abstract members. Even we can have an abstract class only with non abstract members. For example:

abstract class absClass
{
    public void NonAbstractMethod()
    {
        Console.WriteLine("NonAbstract Method");
    }
}

A sample program that explains abstract classes:

using System;

namespace abstractSample
{
      //Creating an Abstract Class
      abstract class absClass
      {
            //A Non abstract method
            public int AddTwoNumbers(int Num1, int Num2)
            {
                return Num1 + Num2;
            }

            //An abstract method, to be
            //overridden in derived class
            public abstract int MultiplyTwoNumbers(int Num1, int Num2);
      }

      //A Child Class of absClass
      class absDerived:absClass
      {
            [STAThread]
            static void Main(string[] args)
            {
               //You can create an
               //instance of the derived class

               absDerived calculate = new absDerived();
               int added = calculate.AddTwoNumbers(10,20);
               int multiplied = calculate.MultiplyTwoNumbers(10,20);
               Console.WriteLine("Added : {0}, 
                       Multiplied : {1}", added, multiplied);
            }

            //using override keyword,
            //implementing the abstract method
            //MultiplyTwoNumbers
            public override int MultiplyTwoNumbers(int Num1, int Num2)
            {
                return Num1 * Num2;
            }
      }
}

In the above sample, you can see that the abstract class absClass contains two methods AddTwoNumbers and MultiplyTwoNumbers. AddTwoNumbers is a non-abstract method which contains implementation and MultiplyTwoNumbers is an abstract method that does not contain implementation.

The class absDerived is derived from absClass and the MultiplyTwoNumbers is implemented on absDerived. Within the Main, an instance (calculate) of the absDerived is created, and calls AddTwoNumbers and MultiplyTwoNumbers. You can derive an abstract class from another abstract class. In that case, in the child class it is optional to make the implementation of the abstract methods of the parent class.

Example

//Abstract Class1
abstract class absClass1
{
    public abstract int AddTwoNumbers(int Num1, int Num2);
    public abstract int MultiplyTwoNumbers(int Num1, int Num2);
}

//Abstract Class2
abstract class absClass2:absClass1
{
    //Implementing AddTwoNumbers
    public override int AddTwoNumbers(int Num1, int Num2)
    {
        return Num1+Num2;
    }
}

//Derived class from absClass2
class absDerived:absClass2
{
    //Implementing MultiplyTwoNumbers
    public override int MultiplyTwoNumbers(int Num1, int Num2)
    {
        return Num1*Num2;
    }
}

In the above example, absClass1 contains two abstract methods AddTwoNumbers and MultiplyTwoNumbers. The AddTwoNumbers is implemented in the derived class absClass2. The class absDerived is derived from absClass2 and the MultiplyTwoNumbers is implemented there.

Abstract properties

Following is an example of implementing abstract properties in a class.

//Abstract Class with abstract properties
abstract class absClass
{
    protected int myNumber;
    public abstract int numbers
    {
        get;
        set;
    }
}

class absDerived:absClass
{
    //Implementing abstract properties
    public override int numbers
    {
        get
        {
            return myNumber;
        }
        set
        {
            myNumber = value;
        }
    }
}

In the above example, there is a protected member declared in the abstract class. The get/set properties for the member variable myNumber is defined in the derived class absDerived.

Important rules applied to abstract classes

An abstract class cannot be a sealed class. I.e. the following declaration is incorrect.

//Incorrect
abstract sealed class absClass
{
}

Declaration of abstract methods are only allowed in abstract classes.

An abstract method cannot be private.

//Incorrect
private abstract int MultiplyTwoNumbers();

The access modifier of the abstract method should be same in both the abstract class and its derived class. If you declare an abstract method as protected, it should be protected in its derived class. Otherwise, the compiler will raise an error.

An abstract method cannot have the modifier virtual. Because an abstract method is implicitly virtual.

//Incorrect
public abstract virtual int MultiplyTwoNumbers();

An abstract member cannot be static.

//Incorrect
publpublic abstract static int MultiplyTwoNumbers();

Abstract class vs. Interface

An abstract class can have abstract members as well non abstract members. But in an interface all the members are implicitly abstract and all the members of the interface must override to its derived class.

An example of interface:

interface iSampleInterface
{
  //All methods are automaticall abstract
  int AddNumbers(int Num1, int Num2);
  int MultiplyNumbers(int Num1, int Num2);
}

Defining an abstract class with abstract members has the same effect to defining an interface.

The members of the interface are public with no implementation. Abstract classes can have protected parts, static methods, etc.

A class can inherit one or more interfaces, but only one abstract class.

Abstract classes can add more functionality without destroying the child classes that were using the old version. In an interface, creation of additional functions will have an effect on its child classes, due to the necessary implementation of interface methods to classes.

The selection of interface or abstract class depends on the need and design of your project. You can make an abstract class, interface or combination of both depending on your needs.

您可能感兴趣的与本文相关的镜像

Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

[root@VM-24-11-opencloudos application]# java -Dorg.bouncycastle.disable.jce.check=true -jar yami-shop.jar 11:31:34,663 |-INFO in ch.qos.logback.classic.LoggerContext[default] - This is logback-classic version 1.4.7 11:31:34,728 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml] 11:31:34,729 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml] 11:31:34,737 |-INFO in ch.qos.logback.classic.BasicConfigurator@169e6180 - Setting up default configuration. 11:31:35,817 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@35aea049 - URL [jar:file:/opt/application/yami-shop.jar!/BOOT-INF/classes!/logback/logback-dev.xml] is not of type file 11:31:35,923 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@7205765b - Adding [jar:file:/opt/application/yami-shop.jar!/BOOT-INF/lib/spring-boot-3.0.7.jar!/org/springframework/boot/logging/logback/defaults.xml] to configuration watch list. 11:31:35,923 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@35aea049 - URL [jar:file:/opt/application/yami-shop.jar!/BOOT-INF/lib/spring-boot-3.0.7.jar!/org/springframework/boot/logging/logback/defaults.xml] is not of type file 11:31:35,928 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word clr with class [org.springframework.boot.logging.logback.ColorConverter] 11:31:35,928 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word wex with class [org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter] 11:31:35,928 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word wEx with class [org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter] 11:31:35,932 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@7205765b - Adding [jar:file:/opt/application/yami-shop.jar!/BOOT-INF/lib/spring-boot-3.0.7.jar!/org/springframework/boot/logging/logback/console-appender.xml] to configuration watch list. 11:31:35,932 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@35aea049 - URL [jar:file:/opt/application/yami-shop.jar!/BOOT-INF/lib/spring-boot-3.0.7.jar!/org/springframework/boot/logging/logback/console-appender.xml] is not of type file 11:31:35,999 |-INFO in ch.qos.logback.classic.model.processor.ConfigurationModelHandler - Registering a new ReconfigureOnChangeTask ReconfigureOnChangeTask(born:1748921495996) 11:31:35,999 |-INFO in ch.qos.logback.classic.model.processor.ConfigurationModelHandler - Will scan for changes in [jar:file:/opt/application/yami-shop.jar!/BOOT-INF/classes!/logback/logback-dev.xml] 11:31:35,999 |-INFO in ch.qos.logback.classic.model.processor.ConfigurationModelHandler - Setting ReconfigureOnChangeTask scanning period to 1 minutes 11:31:36,005 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [org.apache.catalina.startup.DigesterFactory] to ERROR 11:31:36,005 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating ERROR level on Logger[org.apache.catalina.startup.DigesterFactory] onto the JUL framework 11:31:36,010 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [org.apache.catalina.util.LifecycleBase] to ERROR 11:31:36,011 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating ERROR level on Logger[org.apache.catalina.util.LifecycleBase] onto the JUL framework 11:31:36,011 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [org.apache.coyote.http11.Http11NioProtocol] to WARN 11:31:36,011 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating WARN level on Logger[org.apache.coyote.http11.Http11NioProtocol] onto the JUL framework 11:31:36,011 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [org.apache.sshd.common.util.SecurityUtils] to WARN 11:31:36,011 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating WARN level on Logger[org.apache.sshd.common.util.SecurityUtils] onto the JUL framework 11:31:36,011 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [org.apache.tomcat.util.net.NioSelectorPool] to WARN 11:31:36,011 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating WARN level on Logger[org.apache.tomcat.util.net.NioSelectorPool] onto the JUL framework 11:31:36,011 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [org.eclipse.jetty.util.component.AbstractLifeCycle] to ERROR 11:31:36,011 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating ERROR level on Logger[org.eclipse.jetty.util.component.AbstractLifeCycle] onto the JUL framework 11:31:36,011 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [org.hibernate.validator.internal.util.Version] to WARN 11:31:36,011 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating WARN level on Logger[org.hibernate.validator.internal.util.Version] onto the JUL framework 11:31:36,011 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [org.springframework.boot.actuate.endpoint.jmx] to WARN 11:31:36,011 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating WARN level on Logger[org.springframework.boot.actuate.endpoint.jmx] onto the JUL framework 11:31:36,011 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [CONSOLE] 11:31:36,012 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 11:31:36,019 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 11:31:36,043 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [DefaultFile] 11:31:36,043 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 11:31:36,056 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@586127428 - No compression will be used 11:31:36,058 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@586127428 - Will use the pattern ./log/%d{yyyy-MM-dd}/admin-%d{yyyy-MM-dd}-%i.log for the active file 11:31:36,089 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@6283d8b8 - The date pattern is 'yyyy-MM-dd' from file name pattern './log/%d{yyyy-MM-dd}/admin-%d{yyyy-MM-dd}-%i.log'. 11:31:36,089 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@6283d8b8 - Roll-over at midnight. 11:31:36,099 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@6283d8b8 - Setting initial period to 2025-06-03T03:23:38.477Z 11:31:36,100 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@6283d8b8 - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead 11:31:36,100 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@6283d8b8 - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy 11:31:36,110 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[DefaultFile] - Active log file name: ./log/admin.log 11:31:36,110 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[DefaultFile] - File property is set to [./log/admin.log] 11:31:36,118 |-INFO in ch.qos.logback.classic.model.processor.RootLoggerModelHandler - Setting level of ROOT logger to INFO 11:31:36,118 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating INFO level on Logger[ROOT] onto the JUL framework 11:31:36,119 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [CONSOLE] to Logger[ROOT] 11:31:36,119 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [DefaultFile] to Logger[ROOT] 11:31:36,119 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [com.yami.shop] to DEBUG 11:31:36,119 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating DEBUG level on Logger[com.yami.shop] onto the JUL framework 11:31:36,119 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [springfox.documentation.swagger2] to OFF 11:31:36,119 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating OFF level on Logger[springfox.documentation.swagger2] onto the JUL framework 11:31:36,119 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [io.swagger.models.parameters] to OFF 11:31:36,119 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating OFF level on Logger[io.swagger.models.parameters] onto the JUL framework 11:31:36,119 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [springfox.documentation.swagger.readers.operation.OperationImplicitParameterReader] to OFF 11:31:36,119 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating OFF level on Logger[springfox.documentation.swagger.readers.operation.OperationImplicitParameterReader] onto the JUL framework 11:31:36,119 |-INFO in ch.qos.logback.classic.model.processor.LoggerModelHandler - Setting level of logger [springfox.documentation.spring.web.readers.operation] to OFF 11:31:36,119 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@47987356 - Propagating OFF level on Logger[springfox.documentation.spring.web.readers.operation] onto the JUL framework 11:31:36,119 |-INFO in ch.qos.logback.core.model.processor.DefaultProcessor@3b6ddd1d - End of configuration. 11:31:36,120 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@3f6b0be5 - Registering current configuration as safe fallback point .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. | .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. | | | ____ ____ | || | __ | || | _____ | || | _____ | || | _ _ | || | _____ | | | ||_ \ / _|| || | / \ | || | |_ _| | || | |_ _| | || | | | | | | || | |_ _| | | | | | \/ | | || | / /\ \ | || | | | | || | | | | || | | |__| |_ | || | | | | | | | | |\ /| | | || | / ____ \ | || | | | _ | || | | | _ | || | |____ _| | || | _ | | | | | | _| |_\/_| |_ | || | _/ / \ \_ | || | _| |__/ | | || | _| |__/ | | || | _| |_ | || | | |_' | | | | ||_____||_____|| || ||____| |____|| || | |________| | || | |________| | || | |_____| | || | `.___.' | | | | | || | | || | | || | | || | | || | | | | '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' | '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' [traceId:] 2025-06-03T11:31:36.454+08:00 INFO 335254 --- [ main] com.yami.shop.admin.WebApplication : Starting WebApplication using Java 17.0.8 with PID 335254 (/opt/application/yami-shop.jar started by root in /opt/application) [traceId:] 2025-06-03T11:31:36.466+08:00 DEBUG 335254 --- [ main] com.yami.shop.admin.WebApplication : Running with Spring Boot v3.0.7, Spring v6.0.9 [traceId:] 2025-06-03T11:31:36.467+08:00 INFO 335254 --- [ main] com.yami.shop.admin.WebApplication : The following 1 profile is active: "tks-test" [traceId:] 2025-06-03T11:31:40.140+08:00 INFO 335254 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode [traceId:] 2025-06-03T11:31:40.144+08:00 INFO 335254 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode. [traceId:] 2025-06-03T11:31:40.193+08:00 INFO 335254 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 21 ms. Found 0 Redis repository interfaces. [traceId:] 2025-06-03T11:31:41.223+08:00 WARN 335254 --- [ main] ocalVariableTableParameterNameDiscoverer : Using deprecated '-debug' fallback for parameter name resolution. Compile the affected code with '-parameters' instead or avoid its introspection: com.yami.shop.common.aspect.RedisLockAspect [traceId:] 2025-06-03T11:31:41.225+08:00 WARN 335254 --- [ main] ocalVariableTableParameterNameDiscoverer : Using deprecated '-debug' fallback for parameter name resolution. Compile the affected code with '-parameters' instead or avoid its introspection: com.yami.shop.sys.aspect.SysLogAspect [traceId:] 2025-06-03T11:31:42.570+08:00 INFO 335254 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8085 (http) [traceId:] 2025-06-03T11:31:42.588+08:00 INFO 335254 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] [traceId:] 2025-06-03T11:31:42.589+08:00 INFO 335254 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.8] [traceId:] 2025-06-03T11:31:42.734+08:00 INFO 335254 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext [traceId:] 2025-06-03T11:31:42.736+08:00 INFO 335254 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5532 ms [traceId:] 2025-06-03T11:31:42.751+08:00 INFO 335254 --- [ main] c.y.s.s.c.a.DefaultAuthConfigAdapter : not implement other AuthConfigAdapter, use DefaultAuthConfigAdapter... all url need auth... [traceId:] 2025-06-03T11:31:43.284+08:00 INFO 335254 --- [ main] org.redisson.Version : Redisson 3.19.3 [traceId:] 2025-06-03T11:31:43.908+08:00 INFO 335254 --- [isson-netty-2-7] o.r.c.pool.MasterPubSubConnectionPool : 1 connections initialized for localhost/127.0.0.1:6379 [traceId:] 2025-06-03T11:31:43.971+08:00 INFO 335254 --- [sson-netty-2-20] o.r.c.pool.MasterConnectionPool : 24 connections initialized for localhost/127.0.0.1:6379 [traceId:] 2025-06-03T11:31:45.557+08:00 ERROR 335254 --- [ main] c.b.m.core.MybatisConfiguration : mapper[com.yami.shop.dao.BasketMapper.getShopCartItems] is ignored, because it exists, maybe from xml file [traceId:] 2025-06-03T11:31:46.202+08:00 WARN 335254 --- [ main] c.b.m.core.injector.AbstractMethod : [com.yami.shop.dao.DistributionProdMapper.selectPage] Has been loaded by XML or SqlProvider or Mybatis's Annotation, so ignoring this injection for [class com.baomidou.mybatisplus.core.injector.methods.SelectPage] [traceId:] 2025-06-03T11:31:48.093+08:00 WARN 335254 --- [ main] c.b.m.core.injector.AbstractMethod : [com.yami.shop.dao.UserMerchantMchMapper.selectPage] Has been loaded by XML or SqlProvider or Mybatis's Annotation, so ignoring this injection for [class com.baomidou.mybatisplus.core.injector.methods.SelectPage] [traceId:] 2025-06-03T11:31:50.519+08:00 DEBUG 335254 --- [ main] c.y.s.c.t.TraceThreadPoolTaskExceutor : Initializing ExecutorService [traceId:] 2025-06-03T11:31:50.521+08:00 DEBUG 335254 --- [ main] c.y.s.c.t.TraceThreadPoolTaskExceutor : Initializing ExecutorService 'taskExecutor' [traceId:] 2025-06-03T11:31:53.142+08:00 WARN 335254 --- [ main] c.b.m.core.metadata.TableInfoHelper : Can not find table primary key in Class: "com.yami.shop.bean.model.PayInfo". [traceId:] 2025-06-03T11:31:53.142+08:00 WARN 335254 --- [ main] c.b.m.core.injector.DefaultSqlInjector : class com.yami.shop.bean.model.PayInfo ,Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method. [traceId:] 2025-06-03T11:31:53.669+08:00 INFO 335254 --- [ main] c.yami.shop.common.util.sms.AliSmsUtils : 阿里短信平台初始化成功! [traceId:] 2025-06-03T11:31:53.876+08:00 INFO 335254 --- [ main] com.anji.captcha.util.ImageUtils : 自定义resource底图:[SLIDING_BLOCK=[Ljava.lang.String;@4b508371, ORIGINAL=[Ljava.lang.String;@41143873, PIC_CLICK=[Ljava.lang.String;@21f50d2c] [traceId:] 2025-06-03T11:31:53.881+08:00 INFO 335254 --- [ main] c.a.c.s.impl.CaptchaServiceFactory : supported-captchaCache-service:[redis, local] [traceId:] 2025-06-03T11:31:53.887+08:00 INFO 335254 --- [ main] c.a.c.s.impl.CaptchaServiceFactory : supported-captchaTypes-service:[clickWord, default, blockPuzzle] [traceId:] 2025-06-03T11:31:53.887+08:00 INFO 335254 --- [ main] c.a.c.s.i.BlockPuzzleCaptchaServiceImpl : --->>>初始化验证码底图<<<---blockPuzzle [traceId:] 2025-06-03T11:31:54.805+08:00 WARN 335254 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenAes' defined in class path resource [com/yami/shop/common/config/ShopBeanConfig.class]: Failed to instantiate [cn.hutool.crypto.symmetric.AES]: Factory method 'tokenAes' threw exception with message: SecurityException: JCE cannot authenticate the provider BC [traceId:] 2025-06-03T11:31:54.814+08:00 DEBUG 335254 --- [ main] c.y.s.c.t.TraceThreadPoolTaskExceutor : Shutting down ExecutorService 'taskExecutor' [traceId:] 2025-06-03T11:31:54.858+08:00 INFO 335254 --- [lientSelector_1] RocketmqRemoting : closeChannel: close the connection to remote address[47.115.51.7:9876] result: true [traceId:] 2025-06-03T11:31:54.861+08:00 INFO 335254 --- [lientSelector_1] RocketmqRemoting : closeChannel: close the connection to remote address[47.115.51.7:10911] result: true [traceId:] 2025-06-03T11:31:54.907+08:00 INFO 335254 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] [traceId:] 2025-06-03T11:31:54.946+08:00 INFO 335254 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger : Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. [traceId:] 2025-06-03T11:31:54.986+08:00 ERROR 335254 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenAes' defined in class path resource [com/yami/shop/common/config/ShopBeanConfig.class]: Failed to instantiate [cn.hutool.crypto.symmetric.AES]: Factory method 'tokenAes' threw exception with message: SecurityException: JCE cannot authenticate the provider BC at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:659) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:493) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1332) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1162) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:941) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) at com.yami.shop.admin.WebApplication.main(WebApplication.java:30) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) at org.springframework.boot.loader.Launcher.launch(Launcher.java:95) at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [cn.hutool.crypto.symmetric.AES]: Factory method 'tokenAes' threw exception with message: SecurityException: JCE cannot authenticate the provider BC at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ... 27 common frames omitted Caused by: cn.hutool.crypto.CryptoException: SecurityException: JCE cannot authenticate the provider BC at cn.hutool.crypto.SecureUtil.createCipher(SecureUtil.java:1034) at cn.hutool.crypto.CipherWrapper.<init>(CipherWrapper.java:39) at cn.hutool.crypto.symmetric.SymmetricCrypto.init(SymmetricCrypto.java:150) at cn.hutool.crypto.symmetric.SymmetricCrypto.<init>(SymmetricCrypto.java:127) at cn.hutool.crypto.symmetric.SymmetricCrypto.<init>(SymmetricCrypto.java:115) at cn.hutool.crypto.symmetric.SymmetricCrypto.<init>(SymmetricCrypto.java:104) at cn.hutool.crypto.symmetric.SymmetricCrypto.<init>(SymmetricCrypto.java:83) at cn.hutool.crypto.symmetric.AES.<init>(AES.java:50) at com.yami.shop.common.config.ShopBeanConfig.tokenAes(ShopBeanConfig.java:27) at com.yami.shop.common.config.ShopBeanConfig$$SpringCGLIB$$0.CGLIB$tokenAes$2(<generated>) at com.yami.shop.common.config.ShopBeanConfig$$SpringCGLIB$$2.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) at com.yami.shop.common.config.ShopBeanConfig$$SpringCGLIB$$0.tokenAes(<generated>) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139) ... 28 common frames omitted Caused by: java.lang.SecurityException: JCE cannot authenticate the provider BC at java.base/javax.crypto.Cipher.getInstance(Cipher.java:722) at cn.hutool.crypto.SecureUtil.createCipher(SecureUtil.java:1032) ... 46 common frames omitted Caused by: java.lang.IllegalStateException: zip file closed at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:839) at java.base/java.util.zip.ZipFile.getManifestName(ZipFile.java:1065) at java.base/java.util.zip.ZipFile$1.getManifestName(ZipFile.java:1108) at java.base/javax.crypto.JarVerifier.verifySingleJar(JarVerifier.java:464) at java.base/javax.crypto.JarVerifier.verifyJars(JarVerifier.java:320) at java.base/javax.crypto.JarVerifier.verify(JarVerifier.java:263) at java.base/javax.crypto.ProviderVerifier.verify(ProviderVerifier.java:130) at java.base/javax.crypto.JceSecurity.verifyProvider(JceSecurity.java:190) at java.base/javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:218) at java.base/javax.crypto.Cipher.getInstance(Cipher.java:718) ... 47 common frames omitted 以上方案都尝试过了还是报错
06-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值