SpringBoot启动遇到的异常问题

时间:2025-03-08 08:57:02
1、 问题
SpringBoot本身需要引入自身的一个parent,但是pom里面一般都已经存在了一个parent,这时就不能在引入springBoot的parent


解决方案:
<dependency>
            <groupId></groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.3.</version>
        </dependency>


        <dependency>
            <groupId></groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>


2、异常:
Exception in thread "main" : Cannot instantiate interface :
。。。。。。
Caused by: : org/springframework/context/event/GenericApplicationListener
解决方案:
这个问题可能是由于Spring的版本低导致,升级spring版本。亲测到4.2.可以
<>4.2.</>


3、异常:



Exception in thread "main" : LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org..Log4jLoggerFactory loaded from file:/D:/maven/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/ Object of class [org..Log4jLoggerFactory] must be an instance of class
at (:346)
at (:221)

解决方案:
这个异常是由于打印日志的jar冲突导致,SpringBoot本身有打印日志的功能,如果跟本地的冲突,就需要去掉,如下
   <dependency>
            <groupId></groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.3.</version>
            <exclusions>
                <exclusion>
                    <groupId></groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

4、异常


Cannot instantiate factory class:


Caused by: : Class can not access a member of class with modifiers ""


解决方案:
这种可以检查的版本,可能是版本不兼容,我这里一开始设置的1.5.,一直出异常,后来SpringBoot的版本改成全部改成1.3.  把Spring的版本改成4.2.,通过


5、 异常:

        SpringBoot启动

-Unregistering JMX-exposed beans on shutdown ,tomcat也没有运行


可能原因1:

看看是否屏蔽了,检查 <artifactId>spring-boot-starter-web</artifactId> 这个下面是否屏蔽了spring-boot-starter-tomcat,
如果有,请去掉
<exclusion>
                    <groupId></groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
可能原因2:
<dependency>
<groupId></groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
将<scope>provided</scope>注释掉
6、异常:


Caused by: : org/springframework/beans/factory/ObjectProvider

Caused by: :

        解决方案

这个异常最蛋疼,搞了半天是SpringBoot的版本不兼容,切换了一个版本到1.3. 这里就好了
        <dependency>
            <groupId></groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.3.</version>
            <exclusions>
                <exclusion>
                    <groupId></groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

建议把<groupId></groupId>这下下面的版本都改成1.3.


7、异常:
: .<init>(Lorg/springframework/expression/spel/SpelCompilerMode;Ljava/lang/ClassLoader

解决方案:

        缺少jar

    <dependency>
                <groupId></groupId>
                <artifactId>spring-expression</artifactId>
                <version>4.2.</version>
            </dependency>