Recently learning to use Spring boot. Use MAVEN to create a project that references only the spring boot-related jar packages that need to be used, except that there are no configurations.
Write a simple example as follows:
1 PackageCom.torlight;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;5 Importorg.springframework.boot.autoconfigure.SpringBootApplication;6 Importorg.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;7 ImportOrg.springframework.context.ApplicationContext;8 ImportOrg.springframework.context.ConfigurableApplicationContext;9 Ten One /** A * @since2017.05.06 - * @authorAcer - * the */ - @SpringBootApplication - Public classApplication { - + Public Static voidMain (string[] args) { -ApplicationContext appctx= springapplication.run (application.class, args); + ASystem.out.println ("appctx.getbeandefinitioncount=" +Appctx.getbeandefinitioncount ()); at Try { - ((Configurableapplicationcontext) appctx). Close (); -}Catch(Exception e) {/*Ignore*/ } - } -}
After running the program, the console outputs an error log:
017-05-06 22:44:18.868 WARN 41648---[Restartedmain] ationconfigembeddedwebapplicationcontext:exception encountered D Uring 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/D Atasourceconfiguration$tomcat.class]: Bean instantiation via factory method failed; Nested exception is org.springframework.beans.BeanInstantiationException:Failed to instantiate [ Org.apache.tomcat.jdbc.pool.DataSource]: Factory method ' DataSource ' threw exception; Nested exception is org.springframework.boot.autoconfigure.jdbc.datasourceproperties$ Datasourcebeancreationexception:cannot Determine embedded database driver class for database type NONE. If you want a embedded database, put a supported one on the classpath. If you have the database settings to is loaded from a particular profiles you may need to active it (no profiles is currently Active).
2017-05-06 22:44:18.871 INFO 41648---[restartedmain] o.apache.catalina.core.standardservice:stopping service Tomcat
2017-05-06 22:44:18.902 INFO 41648---[Restartedmain] utoconfigurationreportlogginginitializer:
Error starting ApplicationContext. To display the Auto-configuration report re-run your application with ' debug ' enabled.
2017-05-06 22:44:18.907 ERROR 41648---[Restartedmain] o.s.b.d.loggingfailureanalysisreporter:
***************************
Application FAILED to START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want a embedded database, put a supported one on the classpath. If you have the database settings to is loaded from a particular profiles you may need to active it (no profiles is currently Active).
This is because spring Boot defaults to loading the Org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration class, and the Datasourceautoconfiguration class uses the @Configuration annotations into Spring
Injected the DataSource bean. Because there is no configuration information related to datasource in the project, the spring creation DataSource Bean will be error-free due to lack of relevant information.
Because I just use spring boot to write some very simple examples to learn it, add @enableautoconfiguration on the application class (exclude={ Datasourceautoconfiguration.class})
Prevent spring boot from automatically injecting datasource beans
1 PackageCom.torlight;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;5 Importorg.springframework.boot.autoconfigure.SpringBootApplication;6 Importorg.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;7 ImportOrg.springframework.context.ApplicationContext;8 ImportOrg.springframework.context.ConfigurableApplicationContext;9 Ten One /** A * @since2017.05.06 - * @authorAcer - * the */ - @SpringBootApplication - @EnableAutoConfiguration (Exclude={datasourceautoconfiguration.class}) - Public classApplication { + - Public Static voidMain (string[] args) { +ApplicationContext appctx= springapplication.run (application.class, args); A atSystem.out.println ("appctx.getbeandefinitioncount=" +Appctx.getbeandefinitioncount ()); - Try { - ((Configurableapplicationcontext) appctx). Close (); -}Catch(Exception e) {/*Ignore*/ } - } -}
spriing Boot Boot error: Cannot determine embedded database driver class for database type NONE