2016-08-15 237 views
3

我在這裏確實需要幫助.. 我試圖創建simple webapps具有依賴關係的springboot:web,postgresql,jdbc,vaadin。 當開始運行我的應用程序時,應用程序將不會啓動並引發異常。 指示「..no類型爲JdbcTemplate的合格bean」的異常。 在stackoverflow的一些建議添加神器spring-boot-starter-jdbc,但我的POM已經做到了,仍然無法工作。通過字段'jdbcTemplate'表示的不滿意的依賴關係

下面我的配置

的src /主/資源/ application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/sehati 
spring.datasource.username=sehati 
spring.datasource.password=password 

的pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.sehatigroup</groupId> 
    <artifactId>siapotek</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>siapotek</name> 
    <description>Demo project for Spring Boot</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.4.0.RELEASE</version> 
     <relativePath/> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-jdbc</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-security</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>com.vaadin</groupId> 
      <artifactId>vaadin-spring-boot-starter</artifactId> 
      <version>1.0.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.postgresql</groupId> 
      <artifactId>postgresql</artifactId> 
      <scope>runtime</scope> 
     </dependency> 

     <!-- 
     <dependency> 
      <groupId>com.h2database</groupId> 
      <artifactId>h2</artifactId> 
     </dependency> 
     --> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-jersey</artifactId> 
     </dependency> 
    </dependencies> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>com.vaadin</groupId> 
       <artifactId>vaadin-bom</artifactId> 
       <version>7.6.3</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

主要類:

@SpringBootApplication 
public class SiaApplication { 

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

VadinUI :

@SpringUI 
@Theme("valo") 
public class SehatiDashboardUI extends UI { 
    @Override 
    protected void init(VaadinRequest request) { 
     setContent(new Label("Hello World")); 
    } 
} 

Spring組件:

@Component 
public class LookupService { 

    @Autowired 
    private JdbcTemplate jdbcTemplate; 

    public List<Lookup> findAll() { 
     return jdbcTemplate.query("select id, type, label, name from lookup", 
       (rs, rowNum) -> new Lookup(rs.getLong("id"), rs.getString("type"), rs.getString("label"), rs.getString("label"))); 
    } 
} 

控制檯輸出:

. ____   _   __ _ _ 
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \ 
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 
\\/ ___)| |_)| | | | | || (_| | )))) 
    ' |____| .__|_| |_|_| |_\__, |//// 
=========|_|==============|___/=/_/_/_/ 
:: Spring Boot ::  (v1.4.0.RELEASE) 

2016-08-15 07:03:09.329 INFO 1387 --- [   main] com.sehatigroup.SiaApplication   : Starting SiaApplication on learn2fly with PID 1387 (/home/hameed/workspace/siapotek/target/classes started by hameed in /home/hameed/workspace/siapotek) 
2016-08-15 07:03:09.333 INFO 1387 --- [   main] com.sehatigroup.SiaApplication   : No active profile set, falling back to default profiles: default 
2016-08-15 07:03:09.530 INFO 1387 --- [   main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]5656be13: startup date [Mon Aug 15 07:03:09 WIB 2016]; root of context hierarchy 
2016-08-15 07:03:11.329 WARN 1387 --- [   main] o.s.c.a.ConfigurationClassPostProcessor : Cannot enhance @Configuration bean definition 'com.vaadin.spring.VaadinConfiguration' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'. 
2016-08-15 07:03:11.892 INFO 1387 --- [   main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2016-08-15 07:03:12.069 INFO 1387 --- [   main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$666445bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
2016-08-15 07:03:12.776 INFO 1387 --- [   main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 
2016-08-15 07:03:12.795 INFO 1387 --- [   main] o.apache.catalina.core.StandardService : Starting service Tomcat 
2016-08-15 07:03:12.797 INFO 1387 --- [   main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.4 
2016-08-15 07:03:12.931 INFO 1387 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]  : Initializing Spring embedded WebApplicationContext 
2016-08-15 07:03:12.932 INFO 1387 --- [ost-startStop-1] o.s.web.context.ContextLoader   : Root WebApplicationContext: initialization completed in 3414 ms 
2016-08-15 07:03:13.065 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration  : Registering Vaadin servlet 
2016-08-15 07:03:13.065 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration  : Servlet will be mapped to URLs [/vaadinServlet/*, /VAADIN/*] 
2016-08-15 07:03:13.086 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration  : Setting servlet init parameters 
2016-08-15 07:03:13.086 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration  : Set servlet init parameter [productionMode] = [false] 
2016-08-15 07:03:13.086 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration  : Set servlet init parameter [resourceCacheTime] = [3600] 
2016-08-15 07:03:13.087 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration  : Set servlet init parameter [heartbeatInterval] = [300] 
2016-08-15 07:03:13.087 INFO 1387 --- [ost-startStop-1] c.v.s.b.i.VaadinServletConfiguration  : Set servlet init parameter [closeIdleSessions] = [false] 
2016-08-15 07:03:13.218 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 
2016-08-15 07:03:13.218 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 
2016-08-15 07:03:13.219 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 
2016-08-15 07:03:13.219 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 
2016-08-15 07:03:13.221 INFO 1387 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*] 
2016-08-15 07:03:13.221 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 
2016-08-15 07:03:13.223 INFO 1387 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'springVaadinServlet' to [/vaadinServlet/*, /VAADIN/*] 
2016-08-15 07:03:13.302 WARN 1387 --- [   main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lookupService': Unsatisfied dependency expressed through field 'jdbcTemplate': No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
2016-08-15 07:03:13.307 INFO 1387 --- [   main] o.apache.catalina.core.StandardService : Stopping service Tomcat 
2016-08-15 07:03:13.338 WARN 1387 --- [   main] o.s.boot.SpringApplication    : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined) 
2016-08-15 07:03:13.355 ERROR 1387 --- [   main] o.s.boot.SpringApplication    : Application startup failed 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lookupService': Unsatisfied dependency expressed through field 'jdbcTemplate': No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at com.sehatigroup.SiaApplication.main(SiaApplication.java:10) [classes/:na] 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency [org.springframework.jdbc.core.JdbcTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1406) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1057) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    ... 19 common frames omitted 

,也是我一直嘗試使用H2數據庫。我的應用程序可以啓動,但似乎數據源連接始終使用來自spring-boot-jdbc(url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa')的預配置數據源,即使我已經在application.properties中描述了新的應用程序。

有人能找到我的項目出了什麼問題嗎? 非常感謝您的幫助。

+0

有你沒有顯示的東西。我最好的猜測是你的系統中有兩個'DataSource'。 'application.properties'中的配置將確保爲您創建一個'DataSource' bean。難道你自己在創建數據源?使用「--debug」運行您的應用程序,您將得到一個報告,解釋爲什麼JdbcTemplateAutoConfiguration未啓用。 –

+0

Hi @Stephane。謝謝你的線索。我只在application.properties和AFAIK中配置了一個數據源,但沒有創建其他數據源。我的完整的eclipse項目可以訪問[這裏](https://www.dropbox.com/s/wgee2bgoc9hkrx8/siapotek.tar.gz?dl=0)。請審查我的項目。 – Midoen

+0

我也嘗試調試項目,但我不知道在eclipse [控制檯](https://www.dropbox.com/s/q0ztkqme89tzukv/console.out?dl=0)中拋出的異常。一個輸出線讓我好奇,它說「跳過(空)配置文件...」,我已經檢查了application.properties已經包含數據源config – Midoen

回答

0

我已經嘗試新的IDE(Eclipse中,STS),創建新的工作區,導入項目,創建新項目但仍然面臨一些問題。

最後我的應用程序可以在刪除我的.m2文件夾後運行良好。但我仍然不知道我的mvn存儲庫中發生了什麼。

 . ____   _   __ _ _ 
    /\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \ 
    (()\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 
    \\/ ___)| |_)| | | | | || (_| | )))) 
     ' |____| .__|_| |_|_| |_\__, |//// 
    =========|_|==============|___/=/_/_/_/ 
    :: Spring Boot ::  (v1.4.0.RELEASE) 

    2016-08-16 06:14:42.381 INFO 2531 --- [   main] com.sehatigroup.SiaApplication   : Starting SiaApplication on learn2fly with PID 2531 (/home/hameed/workspace/siapotek/target/classes started by hameed in /home/hameed/workspace/siapotek) 
    2016-08-16 06:14:42.382 INFO 2531 --- [   main] com.sehatigroup.SiaApplication   : No active profile set, falling back to default profiles: default 
    2016-08-16 06:14:42.382 DEBUG 2531 --- [   main] o.s.boot.SpringApplication    : Loading source class com.sehatigroup.SiaApplication 
    2016-08-16 06:14:42.520 DEBUG 2531 --- [   main] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'file:/home/hameed/workspace/siapotek/target/classes/application.properties' (classpath:/application.properties) 
    2016-08-16 06:14:42.520 DEBUG 2531 --- [   main] o.s.b.c.c.ConfigFileApplicationListener : Skipped (empty) config file 'file:/home/hameed/workspace/siapotek/target/classes/application.properties' (classpath:/application.properties) for profile default 
    2016-08-16 06:14:42.526 INFO 2531 --- [   main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.Annota[email protected]: startup date [Tue Aug 16 06:14:42 WIB 2016]; root of context hierarchy 
    2016-08-16 06:14:42.529 DEBUG 2531 --- [   main] ationConfigEmbeddedWebApplicationContext : Bean factory for org.springframework.boot[email protected]3590fc5b: org.s[email protected]65f095f8: defining beans 

-----CUTTED_TEXT----8< 

    ========================= 
    AUTO-CONFIGURATION REPORT 
    ========================= 


    Positive matches: 
    ----------------- 

     AuthenticationManagerConfiguration matched 
      - @ConditionalOnBean (types: org.springframework.security.config.annotation.ObjectPostProcessor; SearchStrategy: all) found the following [objectPostProcessor] @ConditionalOnMissingBean (types: org.springframework.security.authentication.AuthenticationManager; SearchStrategy: all) found no beans (OnBeanCondition) 

     BootGlobalAuthenticationConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter (OnClassCondition) 

     DataSourceAutoConfiguration matched 
      - @ConditionalOnClass classes found: javax.sql.DataSource,org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition) 

     DataSourceAutoConfiguration#dataSourceInitializer matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer; SearchStrategy: all) found no beans (OnBeanCondition) 

     DataSourceAutoConfiguration.PooledDataSourceConfiguration matched 
      - supported DataSource class found (DataSourceAutoConfiguration.PooledDataSourceCondition) 
      - @ConditionalOnMissingBean (types: javax.sql.DataSource,javax.sql.XADataSource; SearchStrategy: all) found no beans (OnBeanCondition) 

     DataSourceConfiguration.Tomcat matched 
      - @ConditionalOnClass classes found: org.apache.tomcat.jdbc.pool.DataSource (OnClassCondition) 
      - matched (OnPropertyCondition) 

     DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration matched 
      - @ConditionalOnClass classes found: org.apache.tomcat.jdbc.pool.DataSource (OnClassCondition) 

     DataSourceTransactionManagerAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition) 

     DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration matched 
      - @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) found a primary candidate amongst the following [dataSource] (OnBeanCondition) 

     DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration#transactionManager matched 
      - @ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) found no beans (OnBeanCondition) 

     DataSourceTransactionManagerAutoConfiguration.TransactionManagementConfiguration matched 
      - @ConditionalOnMissingBean (types: org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration; SearchStrategy: all) found no beans (OnBeanCondition) 

     DispatcherServletAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition) 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 

     DispatcherServletAutoConfiguration.DispatcherServletConfiguration matched 
      - @ConditionalOnClass classes found: javax.servlet.ServletRegistration (OnClassCondition) 
      - no DispatcherServlet found (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition) 

     DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration matched 
      - @ConditionalOnClass classes found: javax.servlet.ServletRegistration (OnClassCondition) 
      - no ServletRegistrationBean found (DispatcherServletAutoConfiguration.DispatcherServletRegistrationCondition) 

     DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration#dispatcherServletRegistration matched 
      - @ConditionalOnBean (names: dispatcherServlet; types: org.springframework.web.servlet.DispatcherServlet; SearchStrategy: all) found the following [dispatcherServlet, dispatcherServlet] (OnBeanCondition) 

     EmbeddedServletContainerAutoConfiguration matched 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 

     EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat matched 
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.Tomcat (OnClassCondition) 
      - @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: current) found no beans (OnBeanCondition) 

     ErrorMvcAutoConfiguration matched 
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet (OnClassCondition) 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 

     ErrorMvcAutoConfiguration#basicErrorController matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.ErrorController; SearchStrategy: current) found no beans (OnBeanCondition) 

     ErrorMvcAutoConfiguration#conventionErrorViewResolver matched 
      - @ConditionalOnBean (types: org.springframework.web.servlet.DispatcherServlet; SearchStrategy: all) found the following [dispatcherServlet] @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.DefaultErrorViewResolver; SearchStrategy: all) found no beans (OnBeanCondition) 

     ErrorMvcAutoConfiguration#errorAttributes matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.ErrorAttributes; SearchStrategy: current) found no beans (OnBeanCondition) 

     ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration matched 
      - No error template view detected (ErrorMvcAutoConfiguration.ErrorTemplateMissingCondition) 
      - matched (OnPropertyCondition) 

     ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration#beanNameViewResolver matched 
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.BeanNameViewResolver; SearchStrategy: all) found no beans (OnBeanCondition) 

     ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration#defaultErrorView matched 
      - @ConditionalOnMissingBean (names: error; SearchStrategy: all) found no beans (OnBeanCondition) 

     GenericCacheConfiguration matched 
      - Automatic cache type (CacheCondition) 

     HttpEncodingAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.web.filter.CharacterEncodingFilter (OnClassCondition) 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 
      - matched (OnPropertyCondition) 

     HttpEncodingAutoConfiguration#characterEncodingFilter matched 
      - @ConditionalOnMissingBean (types: org.springframework.web.filter.CharacterEncodingFilter; SearchStrategy: all) found no beans (OnBeanCondition) 

     HttpMessageConvertersAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.http.converter.HttpMessageConverter (OnClassCondition) 

     HttpMessageConvertersAutoConfiguration#messageConverters matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.HttpMessageConverters; SearchStrategy: all) found no beans (OnBeanCondition) 

     HttpMessageConvertersAutoConfiguration.StringHttpMessageConverterConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.http.converter.StringHttpMessageConverter (OnClassCondition) 

     HttpMessageConvertersAutoConfiguration.StringHttpMessageConverterConfiguration#stringHttpMessageConverter matched 
      - @ConditionalOnMissingBean (types: org.springframework.http.converter.StringHttpMessageConverter; SearchStrategy: all) found no beans (OnBeanCondition) 


-----CUTTED_TEXT----8< 


     JdbcTemplateAutoConfiguration matched 
      - @ConditionalOnClass classes found: javax.sql.DataSource (OnClassCondition) 
      - @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) found a primary candidate amongst the following [dataSource] (OnBeanCondition) 

     JdbcTemplateAutoConfiguration#jdbcTemplate matched 
      - @ConditionalOnMissingBean (types: org.springframework.jdbc.core.JdbcOperations; SearchStrategy: all) found no beans (OnBeanCondition) 

     JdbcTemplateAutoConfiguration#namedParameterJdbcTemplate matched 
      - @ConditionalOnMissingBean (types: org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; SearchStrategy: all) found no beans (OnBeanCondition) 

     JmxAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.jmx.export.MBeanExporter (OnClassCondition) 
      - matched (OnPropertyCondition) 

     JmxAutoConfiguration#mbeanExporter matched 
      - @ConditionalOnMissingBean (types: org.springframework.jmx.export.MBeanExporter; SearchStrategy: current) found no beans (OnBeanCondition) 

     JmxAutoConfiguration#mbeanServer matched 
      - @ConditionalOnMissingBean (types: javax.management.MBeanServer; SearchStrategy: all) found no beans (OnBeanCondition) 

     JmxAutoConfiguration#objectNamingStrategy matched 
      - @ConditionalOnMissingBean (types: org.springframework.jmx.export.naming.ObjectNamingStrategy; SearchStrategy: current) found no beans (OnBeanCondition) 

     MultipartAutoConfiguration matched 
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver,javax.servlet.MultipartConfigElement (OnClassCondition) 
      - matched (OnPropertyCondition) 

     MultipartAutoConfiguration#multipartConfigElement matched 
      - @ConditionalOnMissingBean (types: javax.servlet.MultipartConfigElement; SearchStrategy: all) found no beans (OnBeanCondition) 

     MultipartAutoConfiguration#multipartResolver matched 
      - @ConditionalOnMissingBean (types: org.springframework.web.multipart.MultipartResolver; SearchStrategy: all) found no beans (OnBeanCondition) 

     NoOpCacheConfiguration matched 
      - Automatic cache type (CacheCondition) 

     PersistenceExceptionTranslationAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor (OnClassCondition) 

     PersistenceExceptionTranslationAutoConfiguration#persistenceExceptionTranslationPostProcessor matched 
      - @ConditionalOnMissingBean (types: org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; SearchStrategy: all) found no beans (OnBeanCondition) 
      - matched (OnPropertyCondition) 

     PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer matched 
      - @ConditionalOnMissingBean (types: org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy: current) found no beans (OnBeanCondition) 

     RedisCacheConfiguration matched 
      - Automatic cache type (CacheCondition) 

     SecurityAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.security.authentication.AuthenticationManager,org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter (OnClassCondition) 

     SecurityAutoConfiguration#authenticationEventPublisher matched 
      - @ConditionalOnMissingBean (types: org.springframework.security.authentication.AuthenticationEventPublisher; SearchStrategy: all) found no beans (OnBeanCondition) 

     SecurityAutoConfiguration#securityProperties matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.security.SecurityProperties; SearchStrategy: all) found no beans (OnBeanCondition) 

     SecurityFilterAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer,org.springframework.security.config.http.SessionCreationPolicy (OnClassCondition) 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 

     SecurityFilterAutoConfiguration#securityFilterChainRegistration matched 
      - @ConditionalOnBean (names: springSecurityFilterChain; SearchStrategy: all) found the following [springSecurityFilterChain] (OnBeanCondition) 

     ServerPropertiesAutoConfiguration matched 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 

     ServerPropertiesAutoConfiguration#serverProperties matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.ServerProperties; SearchStrategy: current) found no beans (OnBeanCondition) 

     SimpleCacheConfiguration matched 
      - Automatic cache type (CacheCondition) 

     SpringApplicationAdminJmxAutoConfiguration matched 
      - matched (OnPropertyCondition) 

     SpringApplicationAdminJmxAutoConfiguration#springApplicationAdminRegistrar matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar; SearchStrategy: all) found no beans (OnBeanCondition) 

     SpringBootWebSecurityConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.security.config.annotation.web.configuration.EnableWebSecurity,org.springframework.security.web.AuthenticationEntryPoint (OnClassCondition) 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 
      - @ConditionalOnMissingBean (types: org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration; SearchStrategy: all) found no beans (OnBeanCondition) 

     SpringBootWebSecurityConfiguration#ignoredPathsWebSecurityConfigurerAdapter matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration$IgnoredPathsWebSecurityConfigurerAdapter; SearchStrategy: all) found no beans (OnBeanCondition) 

     SpringBootWebSecurityConfiguration.ApplicationWebSecurityConfigurerAdapter matched 
      - matched (OnPropertyCondition) 

     TransactionAutoConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.transaction.support.TransactionTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition) 
      - @ConditionalOnSingleCandidate (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) found a primary candidate amongst the following [transactionManager] (OnBeanCondition) 

     TransactionAutoConfiguration#transactionTemplate matched 
      - @ConditionalOnMissingBean (types: org.springframework.transaction.support.TransactionTemplate; SearchStrategy: all) found no beans (OnBeanCondition) 

     VaadinAutoConfiguration matched 
      - @ConditionalOnClass classes found: com.vaadin.spring.annotation.SpringUI (OnClassCondition) 

     VaadinServletConfiguration#vaadinServlet matched 
      - @ConditionalOnMissingBean (types: com.vaadin.server.VaadinServlet; SearchStrategy: all) found no beans (OnBeanCondition) 

     WebClientAutoConfiguration.RestTemplateConfiguration matched 
      - @ConditionalOnClass classes found: org.springframework.web.client.RestTemplate (OnClassCondition) 

     WebClientAutoConfiguration.RestTemplateConfiguration#restTemplateBuilder matched 
      - @ConditionalOnMissingBean (types: org.springframework.boot.web.client.RestTemplateBuilder; SearchStrategy: all) found no beans (OnBeanCondition) 

     WebMvcAutoConfiguration matched 
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet,org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter (OnClassCondition) 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) found no beans (OnBeanCondition) 

     WebMvcAutoConfiguration#hiddenHttpMethodFilter matched 
      - @ConditionalOnMissingBean (types: org.springframework.web.filter.HiddenHttpMethodFilter; SearchStrategy: all) found no beans (OnBeanCondition) 

     WebMvcAutoConfiguration#httpPutFormContentFilter matched 
      - @ConditionalOnMissingBean (types: org.springframework.web.filter.HttpPutFormContentFilter; SearchStrategy: all) found no beans (OnBeanCondition) 

     WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver matched 
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.InternalResourceViewResolver; SearchStrategy: all) found no beans (OnBeanCondition) 

     WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#requestContextFilter matched 
      - @ConditionalOnMissingBean (types: org.springframework.web.context.request.RequestContextListener,org.springframework.web.filter.RequestContextFilter; SearchStrategy: all) found no beans (OnBeanCondition) 

     WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver matched 
      - @ConditionalOnBean (types: org.springframework.web.servlet.ViewResolver; SearchStrategy: all) found the following [defaultViewResolver, beanNameViewResolver, mvcViewResolver] @ConditionalOnMissingBean (names: viewResolver; types: org.springframework.web.servlet.view.ContentNegotiatingViewResolver; SearchStrategy: all) found no beans (OnBeanCondition) 

     WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter.FaviconConfiguration matched 
      - matched (OnPropertyCondition) 

     WebSocketAutoConfiguration matched 
      - @ConditionalOnClass classes found: javax.servlet.Servlet,javax.websocket.server.ServerContainer (OnClassCondition) 
      - found web application StandardServletEnvironment (OnWebApplicationCondition) 

     WebSocketAutoConfiguration.TomcatWebSocketConfiguration matched 
      - @ConditionalOnClass classes found: org.apache.catalina.startup.Tomcat,org.apache.tomcat.websocket.server.WsSci (OnClassCondition) 

     WebSocketAutoConfiguration.TomcatWebSocketConfiguration#websocketContainerCustomizer matched 
      - Required JVM version 1.7 or newer found 1.8 (OnJavaCondition) 
      - @ConditionalOnMissingBean (names: websocketContainerCustomizer; SearchStrategy: all) found no beans (OnBeanCondition) 


     -----CUTTED_TEXT----8< 


    2016-08-16 06:14:47.958 INFO 2531 --- [   main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 
    2016-08-16 06:14:47.964 INFO 2531 --- [   main] com.sehatigroup.SiaApplication   : Started SiaApplication in 6.015 seconds (JVM running for 6.797) 

謝謝

-1

看起來好像您還沒有在任何配置類中創建JdbcTemplate bean,所以Spring在您的應用程序啓動時不知道注入到JdbcTemplate中的內容。

這裏有一個例子演示瞭如何從一個數據源豆在Spring配置設置您的JdbcTemplate:http://www.concretepage.com/spring/jdbc-template-spring-jdbc-integration-example

+0

嗨,亞當。感謝您的建議。由於我使用spring-boot-starter-jdbc,會自動創建jdbcTemplate bean嗎? – Midoen

+0

啊,看來你是正確的:)但是我讀了自述文件,它有以下信息: 「Spring Boot spot H2,一個內存中的關係數據庫引擎,並自動創建一個連接,因爲我們使用的是spring -jdbc,Spring Boot會自動創建一個JdbcTemplate。@Autowired JdbcTemplate字段會自動加載並使其可用。「 鑑於它似乎需要H2來注入JdbcTemplate,是否有一個原因,你已經在你的pom中評論了這個? – Pete

+0

您不需要H2即可獲取JdbcTemplate。只要有一個數據源(在任何數據庫類型上),我們就會自動配置一個JdbcTemplate。 –

相關問題