坑---- Error starting Tomcat context. Exception:org.springframework.beans.factory.BeanCreationExcepti

项目启动时报错,tomcat停止。
报错信息:

[ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: 
org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 
'servletEndpointRegistrar' defined in class path resource 
[org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMv
cServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception 
is org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' 
threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'healthEndpoint' defined in class path resource 

左思右想一直找不到问题所在,最后还是看了https://blog.csdn.net/qq_42145410/article/details/105055280 这个博主的博客才找到问题。

原因在于我的配置文件加载不成功,因为在pom文件中忽略掉了yml文件(我的项目配置文件是yml形式),最后在build中重新加入了yml的配置才能成功,感谢博主。

 <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                    <include>**/*.html</include>
                    <include>**/*.js</include>
                    <include>**/*.css</include>
                    <include>**/*.svg</include>
                    <include>**/**/*.svg</include>
                    <include>**/**/*.png</include>
                    <include>**/*.png</include>
                    <include>**/*.json</include>
                    <include>**/*.jpg</include>
                </includes>
            </resource>
            <!--项目打包时引入导入外部的jar包-->
            <resource>
                <directory>src/main/resources/jars</directory>
                <targetPath>BOOT-INF/jars/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>${project.basedir}\src\main\resources\jars</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

版权声明:本文为qq_44188658原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。