Tag Archives: springboot error

[Solved] Springboot Error: swagger-UI/index.html Access Error 404

Springboot solves swagger UI/index HTML Access Error 404

Recently, I was working on a project to adopt swagger 3.0. After the project is started, access the swagger path: http://localhost:8880/vdmpess -web/swagger-ui/index. HTML reports 404 because webmvcconfig inherits webmvcconfigurationsupport. After inheriting this class, the relevant contents configured in the configuration file will become invalid and the static resource needs to be re specified
the swagger static resource needs to be re specified.

Swagger address in project

Solution:

Adds the address of the specified static resource

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.
                addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }
}

[Solved] SpringBoot Error: org.springframework.http.converter.HttpMessageNotReadableException

SpringBoot Error: org.springframework.http.converter.HttpMessageNotReadableException

 


org.springframework.http.converter.HttpMessageNotReadableException:
Required request body is missing: * * * * *
at.org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:161)
	

After careful investigation, I found that there are no errors in my other codes. Finally, the parameter submission method is wrong, because the @requestbody annotation is mainly used to accept JSON data in post and put methods, so @postmapping should be used here. It’s a perfect solution. I’m really getting farther and farther on the road of rookie

[Solved] Springboot Error: org.apache.catalina.core.ContainerBase : A child container failed during start

Review springboot idea errors:

2021-09-08 21:12:43.851 ERROR 3704 --- [  restartedMain] org.apache.catalina.core.ContainerBase   : A child container failed during start

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: A child container failed during start
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_74]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_74]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:450) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:199) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) [spring-context-5.3.9.jar:5.3.9]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.4.jar:2.5.4]
	at com.sc.myapp.Application.main(Application.java:12) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_74]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_74]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_74]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.4.RELEASE.jar:2.0.4.RELEASE]
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:938) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_74]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_74]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	... 26 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_74]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_74]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	... 34 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
	at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198) [tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_74]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_74]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	... 34 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/apache/tomcat/util/descriptor/tld/TldParser
	at org.apache.jasper.servlet.TldScanner.<init>(TldScanner.java:84) ~[tomcat-embed-jasper-9.0.36.jar:9.0.36]
	at org.apache.jasper.servlet.JasperInitializer.newTldScanner(JasperInitializer.java:100) ~[tomcat-embed-jasper-9.0.36.jar:9.0.36]
	at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:81) ~[tomcat-embed-jasper-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5219) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.52.jar:9.0.52]
	... 40 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.util.descriptor.tld.TldParser
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_74]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_74]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_74]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_74]
	... 45 common frames omitted

2021-09-08 21:12:43.851  INFO 3704 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-09-08 21:12:43.855  WARN 3704 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2021-09-08 21:12:43.860  INFO 3704 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-09-08 21:12:43.873 ERROR 3704 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.4.jar:2.5.4]
	at com.sc.myapp.Application.main(Application.java:12) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_74]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_74]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_74]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.4.RELEASE.jar:2.0.4.RELEASE]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:450) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:199) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[spring-boot-2.5.4.jar:2.5.4]
	... 13 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:938) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-2.5.4.jar:2.5.4]
	... 18 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: A child container failed during start
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_74]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_74]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	... 26 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:938) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_74]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_74]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	... 26 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_74]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_74]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	... 34 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
	at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_74]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_74]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	... 34 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/apache/tomcat/util/descriptor/tld/TldParser
	at org.apache.jasper.servlet.TldScanner.<init>(TldScanner.java:84) ~[tomcat-embed-jasper-9.0.36.jar:9.0.36]
	at org.apache.jasper.servlet.JasperInitializer.newTldScanner(JasperInitializer.java:100) ~[tomcat-embed-jasper-9.0.36.jar:9.0.36]
	at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:81) ~[tomcat-embed-jasper-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5219) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.52.jar:9.0.52]
	... 40 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.util.descriptor.tld.TldParser
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_74]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_74]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_74]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_74]
	... 45 common frames omitted

Solution: remove version

I guess it comes with a conflict with the version we imported

But add:

<!-- add the supportion to jsp files -->
		<dependency>
			<groupId>org.apache.tomcat</groupId>
			<artifactId>tomcat-jsp-api</artifactId>
		</dependency>

Otherwise, an error will be reported

[Solved] SpringBoot Error: This application has no explicit mapping for /error,so you are seeing this as a fallback

[problem phenomenon]

In springboot, when there is no error in the request link and the controller configuration, an error will be prompted when accessing a controller link interface:


This application has no explicit mapping for /error,so you are seeing this as a fallback

[reason]

The request cannot find the corresponding bean for processing. If there is no error in the request link and the controller configuration, it may also be the problem of springbootapplication package scanning, as follows:

By default, the @springbootapplication annotation will only the beans of this package and its sub-packages, resulting in the corresponding controller beans not being loaded into the spring container

[solution]

Scheme I:

Move all controller classes to the same level package or sub package of application class, as shown in the figure:

Scheme II:

If you don’t want to change the file location, you can specify the scanned package with the @ springbootapplication annotation:


@SpringBootApplication(scanBasePackages="com.kid")

How to Solve Springboot Error: Failed to convert value of type

Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Integer’; nested exception is java.lang.NumberFormatException: For input string: “50.5”]

General meaning:
failed to convert the value of type “Java. Lang. string” to the required type “Java. Lang. integer”; Nested exception is java.lang.numberformatexception: for input string: “50.5”]

This kind of error is usually caused by the parameters passed by the front end and the failure of the back end parsing, that is, it is wearing illegal parameters. For example, the upper front end gives me a floating point number, and the back end will fail when the string is parsed into a number!

[Solved] SpringBoot Error: This application has no explicit mapping for /error, so you are seeing this

Springboot project running error:

If you check the directory, the problem lies in the URL in the controller
(1) if: @ requestmapping (“/”)

the URL should be written:

(2) if the URL is like this:

Then @ requestmapping (“/ users”)

is a very simple question… As a result, I took a long walk to look at the XML file and properties for half a day… To record this little problem

[Solved] Error getting bean using springboot: no qualifying bean of type ‘xxx’ available

Recently, I encountered a bug in my work.
the project uses springboot, and uses springcontexthloder, getBean (); No qualifying bean of type ‘xxx’ available

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.tension.web.disabledevaluate.service.DisabledEvaluateService' available

Generally, this error indicates that there is no bean available. Check the code carefully to ensure that this class exists and is injected into spring correctly

Controller:

 public Map loadForm(String round,String instanceId) {
 		//error
        DisabledEvaluateService disabledEvaluateService = SpringContextHolder.getBean(DisabledEvaluateService.class);
 }

Service:

@Service
@Transactional(readOnly = true)
public class DisabledEvaluateService extends CrudService<DisabledEvaluateDao, DisabledEvaluate> {
    public DisabledEvaluate getByBjId(Map map){
        return dao.getByBjIdOrInstanceId(map);
    }

After several hours of exploration, we finally found the information on the Internet because we used the devtools hot deployment plug-in. As a result, when the program starts, we use the classloader rewritten by the devtools hot deployment plug-in instead of the Java default classloader. As a result, some classes may not be loaded correctly, resulting in the inability to obtain beans.

Solution:
this error can be solved without using hot deployment plug-in

SpringBoot uses MyBatis error: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)

1. Error description

  Use SpringBoot to integrate the MyBatis framework, and use mapper-spring-boot-starter to automatically generate MyBatis mapper files, and use mybatis-generator-core to generate MyBatis mapping files.

  SpringBoot version: 2.0.0.RELEASE

  mybatis-spring-boot-starter version: 1.3.2

  mapper-spring-boot-starter version: 1.2.4

  mybatis-generator-core version: 1.3.6

2. Error message

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL). Cause: java.lang.InstantiationException: tk .mybatis.mapper.provider.base.BaseInsertProvider
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java: 77 )
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java: 446 )
    at com.sun.proxy.$Proxy79.insert(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java: 278 )
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java: 58 )
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java: 59 )
    at com.sun.proxy.$Proxy80.insert(Unknown Source)
    at com.imooc.sevice.impl.SysUserServiceImpl.saveUser(SysUserServiceImpl.java: 19 )
    at com.imooc.controller.SysUserController.saveUser(SysUserController.java: 35 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 62 )
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 43 )
    at java.lang.reflect.Method.invoke(Method.java: 498 )
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java: 209 )
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java: 136 )
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java: 102 )
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java: 870 )
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java: 776 )
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java: 87 )
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java: 991 )
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java: 925 )
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java: 978 )
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java: 881 )
    at javax.servlet.http.HttpServlet.service(HttpServlet.java: 661 )
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java: 855 )
    at javax.servlet.http.HttpServlet.service(HttpServlet.java: 742 )
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 231 )
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 )
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java: 52 )
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 )
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 )
    at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java: 123 )
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 )
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 )
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java: 99 )
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java: 107 )
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 )
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 )
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java: 109 )
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java: 107 )
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 )
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 )
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java: 81 )
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java: 107 )
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 )
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 )
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java: 200 )
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java: 107 )
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 193 )
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 166 )
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 199 )
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 96 )
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java: 496 )
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java: 140 )
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java: 81 )
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java: 87 )
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: 342 )
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java: 803 )
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java: 66 )
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java: 790 )
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java: 1459 )
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java: 49 )
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1149 )
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java: 624 )
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java: 61 )
    at java.lang.Thread.run(Thread.java: 748 )
Caused by: org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL). Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base .BaseInsertProvider
    at org.apache.ibatis.builder.annotation.ProviderSqlSource.createSqlSource(ProviderSqlSource.java: 134 )
    at org.apache.ibatis.builder.annotation.ProviderSqlSource.getBoundSql(ProviderSqlSource.java: 102 )
    at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java: 292 )
    at org.apache.ibatis.executor.statement.BaseStatementHandler. <init>(BaseStatementHandler.java:64 )
    at org.apache.ibatis.executor.statement.PreparedStatementHandler. <init>(PreparedStatementHandler.java:40 )
    at org.apache.ibatis.executor.statement.RoutingStatementHandler. <init>(RoutingStatementHandler.java:46 )
    at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java: 558 )
    at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java: 48 )
    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java: 117 )
    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java: 76 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 62 )
    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.$Proxy95.update(Unknown Source)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java: 198 )
    at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java: 185 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 62 )
    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: 433 )
    ... 64 more
Caused by: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseInsertProvider
    at java.lang.Class.newInstance(Class.java: 427 )
    at org.apache.ibatis.builder.annotation.ProviderSqlSource.invokeProviderMethod(ProviderSqlSource.java: 165 )
    at org.apache.ibatis.builder.annotation.ProviderSqlSource.createSqlSource(ProviderSqlSource.java: 116 )
    ... 86 more
Caused by: java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.base.BaseInsertProvider. <init> ()
    at java.lang.Class.getConstructor0(Class.java: 3082 )
    at java.lang.Class.newInstance(Class.java: 412 )
    ... 88 more

3. Problem

  On the startup class of SpringBoot, the wrong package was introduced when using @MapperScan annotation.

  The correct one should be: import tk.mybatis.spring.annotation.MapperScan;

  Wrongly introduced: import org.mybatis.spring.annotation.MapperScan;

[Solved] Springboot Error creating bean with name ‘dataSource’ defined in class path resource

The error message is as follows:

2020-04-02 15:25:15.549 WARN 4360 — [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method ‘dataSource’ threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-04-02 15:25:15.549 INFO 4360 — [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2020-04-02 15:25:15.554 INFO 4360 — [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]

Solution:

Method 1:

Add @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) to the startup class

package com.example.securitycore;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@SpringBootApplication
public class SecurityCoreApplication {

public static void main(String[] args) {
SpringApplication.run(SecurityCoreApplication.class, args);
}

}

Method 2:

Add configuration in application.properties

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/security_demo?characterEncoding=utf-8
spring.datasource.data-username=root
spring .datasource.data-password=root

Springboot Error: There was an unexpected error (type = internal server error, status = 500)

There was an unexpected error (type=Internal Server Error, status=500).
This error was found in running springboot.

There was an unexpected error (type=Internal Server Error, status=500).
Authentication failed for token submission [org.apache.shiro.authc. UsernamePasswordToken – null, rememberMe=false]. Possible unexpected error?(Typical or expected login exceptions should extend from AuthenticationException).
I had to rewrite it and found out that it was caused by Maven and the Thymeleaf dependency was added incorrectly.
Maybe I wrote it and @{} didn’t work correctly, so I took one from the internet and got the wrong one.
The original dependency was this

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

I ended up with this

<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf</artifactId>
    <version>3.0.12.RELEASE</version>
</dependency>

This application has no explicit mapping for /error, so you are seeing this as a fallback.

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Solution:

When springboot is simply tested, the results cannot be displayed correctly. The reason is that the hierarchical structure of the directory is incorrect. The startup class should be placed in the outermost layer of all sub-packages.