If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
程序员文章站
2022-06-02 20:27:41
...
今天学习SpringBoot,使用SpringBoot整合SpringMVC和SpringDataJpa后,写了一个简单的小demo,使用启动类启动后,出现了如下问题:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
按照网上所说的,找到了如下解决办法(加上红框中这句代码):
但是这样做了之后,并没有解决问题,而是出现了一个新的问题:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userDao in com.abc.service.impl.UserServiceImpl required a bean of type 'com.abc.dao.IUserDao' that could not be found.
Action:
Consider defining a bean of type 'com.abc.dao.IUserDao' in your configuration.
于是再去网上找答案,找到了如下解决方法(又加上了包体扫描。如果不是用JPA的实现而是用Mybatis,在Mapper接口上加@Mapper注解即可解决上述问题):
这样的话,上面的问题是解决掉了,但是我的controller根本扫描不到,结果就是浏览器的请求全是404。
无奈之下,只好将这个项目删掉重新写了一遍,以上网上搜索的方法全都没使用,结果却正常。至此问题解决了,但是不知道为何如此灵异!只好先记录下来!
程序启动类:
/**
* <p>Title: SpringbootApplicationRunner</p>
* <p>Description: SpringBoot启动类</p>
* @author Jiang
* @date 2019年3月4日
*/
@SpringBootApplication
public class SpringbootApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplicationRunner.class, args);
}
}
程序启动信息:
13:03:23.036 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
13:03:23.036 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
13:03:23.036 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/D:/Java%e7%8f%ad%e8%af%be%e5%a0%82%e8%b5%84%e6%96%99/workspace4/springboot/target/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.RELEASE)
2019-03-04 13:03:23.597 INFO 4284 --- [ restartedMain] com.abc.SpringbootApplicationRunner : Starting SpringbootApplicationRunner on JN-PC with PID 4284 (started by jiang in D:\Java班课堂资料\workspace4\springboot)
2019-03-04 13:03:23.600 INFO 4284 --- [ restartedMain] com.abc.SpringbootApplicationRunner : No active profile set, falling back to default profiles: default
2019-03-04 13:03:23.680 INFO 4284 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.seraaa@qq.comae5a01d: startup date [Mon Mar 04 13:03:23 CST 2019]; root of context hierarchy
2019-03-04 13:03:25.876 INFO 4284 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$a71426c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-04 13:03:26.996 INFO 4284 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-03-04 13:03:27.039 INFO 4284 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-03-04 13:03:27.039 INFO 4284 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.28
2019-03-04 13:03:27.070 INFO 4284 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [E:\program files\develop\Java\jdk1.8.0_162\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;E:/program files/develop/Java/jdk1.8.0_162/bin/../jre/bin/server;E:/program files/develop/Java/jdk1.8.0_162/bin/../jre/bin;E:/program files/develop/Java/jdk1.8.0_162/bin/../jre/lib/amd64;E:\program files\develop\Java\jdk1.8.0_162\bin;E:\program files\develop\Java\jdk1.8.0_162\bin;E:\program files\develop\apache-maven-3.5.2\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;"E:\program files\develop\Java\jdk1.8.0_162\bin;C:\WINDOWS\system32";C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;E:\program files\develop\MySQL\MySQL Server 5.5\bin;E:\program files\develop\TortoiseSVN\bin;E:\program files\develop\Git\cmd;E:\program files\develop\TortoiseGit\bin;C:\WINDOWS\system32;C:\WINDOWS\System32\OpenSSH\;C:\Users\jiang\AppData\Local\Microsoft\WindowsApps;;E:\program files\develop\eclipse;;.]
2019-03-04 13:03:27.276 INFO 4284 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-03-04 13:03:27.276 INFO 4284 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3596 ms
2019-03-04 13:03:27.540 INFO 4284 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2019-03-04 13:03:27.546 INFO 4284 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-03-04 13:03:27.546 INFO 4284 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-03-04 13:03:27.546 INFO 4284 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-03-04 13:03:27.546 INFO 4284 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-03-04 13:03:27.950 INFO 4284 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-03-04 13:03:28.436 INFO 4284 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-03-04 13:03:28.488 INFO 4284 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-03-04 13:03:28.521 INFO 4284 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-03-04 13:03:28.666 INFO 4284 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.14.Final}
2019-03-04 13:03:28.666 INFO 4284 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-03-04 13:03:28.721 INFO 4284 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-03-04 13:03:28.866 INFO 4284 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-03-04 13:03:29.636 INFO 4284 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-03-04 13:03:30.841 INFO 4284 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.seraaa@qq.comae5a01d: startup date [Mon Mar 04 13:03:23 CST 2019]; root of context hierarchy
2019-03-04 13:03:30.930 WARN 4284 --- [ restartedMain] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-03-04 13:03:31.010 INFO 4284 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/findAll]}" onto public java.util.List<com.abc.domain.User> com.abc.web.controller.UserController.findAll()
2019-03-04 13:03:31.016 INFO 4284 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-03-04 13:03:31.016 INFO 4284 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-03-04 13:03:31.116 INFO 4284 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-03-04 13:03:31.120 INFO 4284 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-03-04 13:03:31.190 INFO 4284 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-03-04 13:03:31.578 INFO 4284 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-03-04 13:03:31.677 INFO 4284 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-03-04 13:03:31.680 INFO 4284 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2019-03-04 13:03:31.686 INFO 4284 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2019-03-04 13:03:31.748 INFO 4284 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-03-04 13:03:31.754 INFO 4284 --- [ restartedMain] com.abc.SpringbootApplicationRunner : Started SpringbootApplicationRunner in 8.693 seconds (JVM running for 9.522)
访问结果:
上一篇: mac的svn下面怎么导出修改的文件?
下一篇: mssql 通用分页存储过程实例
推荐阅读
-
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
-
If you want an embedded database please put a supported one on the classpath
-
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath..
-
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
-
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath
-
cloud 启动报错:If you want an embedded database please put a supported one on the classpath
-
If you want an embedded database please put a supported one on the classpath
-
If you want an embedded database please put a supported one on the classpath
-
spring boot 启动报If you want an embedded database please put a supported one on the classpath
-
配置SpringCloud时错误:If you want an embedded database please put a supported one on the classpath