Gradle H2数据库,具有Spring引导渐变名称ParameterJDBCTemplate/JdbcTemplate

Gradle H2数据库,具有Spring引导渐变名称ParameterJDBCTemplate/JdbcTemplate,gradle,spring-boot,jdbctemplate,Gradle,Spring Boot,Jdbctemplate,我试图设置“H2”来查询非常简单的restful服务,但我在底部遇到了错误:我根本不知道我在哪里出错。任何解决此问题的帮助都会很有帮助。我没有使用弹簧靴的经验。我试着跟着 =================================== 相关代码 @Service public class DBServiesImplementation implements DBServices { @Autowired DBOperation dbo; public DBSe

我试图设置“H2”来查询非常简单的restful服务,但我在底部遇到了错误:我根本不知道我在哪里出错。任何解决此问题的帮助都会很有帮助。我没有使用弹簧靴的经验。我试着跟着

===================================

相关代码

@Service
public class DBServiesImplementation implements DBServices {

    @Autowired
    DBOperation dbo;

    public DBServiesImplementation(final DBOperation dbo){
        this.dbo=dbo;
    }  

    @Override
    public List<Messages> readMessage(String userName) {
        dbo.query("");
        return null;
    }
//.....
}
应用程序属性

spring.datasource.url=jdbc:h2:mem:challenge
spring.datasource.schema=classpath:/schema.sql
spring.datasource.data=classpath:/data.sql
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.driverClassName=com.mysql.jdbc.Driver
日志::

@RestController
public class Controller {


    @Autowired
    DBServices dbServices;

    @RequestMapping(value = "/api/message", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Map<String, String>> getMessages(@AuthenticationPrincipal UserDetails currentUser) {


        List<Messages> list = dbServices.readMessage(currentUser.getUsername());
        list.add(new Messages("Hello", 1));
        Map<String, String> messageMap = retriveMessages();
        return new ResponseEntity<Map<String, String>>(messageMap,
                HttpStatus.OK);
    }
dependencies {
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile ("commons-dbcp:commons-dbcp")   
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('org.springframework.boot:spring-boot-devtools')
    runtime('com.h2database:h2')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
    Exception encountered during context initialization - cancelling refresh attempt: org.spr
ingframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'controller': Unsatisfied dependency expressed through field 'dbServices'; nested exception is org.sp
ringframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'DBServiesImplementation' defined in file [/Users/a/dev/challenge/challenge/bin/org/ws/web
/db/services/DBServiesImplementation.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyExce
ption: Error creating bean with name 'DBOperation' defined in file [/Users/a/dev/challenge/challenge/bin/org/ws/web/db/DBOperation.class]: Unsatisfied dependency expressed through 
constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.jdbc.core.namedparam.NamedParame
terJdbcTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2017-04-30 19:21:13.571  WARN 37050 --- [  restartedMain] o.s.boot.SpringApplication               : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defi
ned in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Initialization of bean failed; nested exception is org.springfra
mework.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' av
ailable)
2017-04-30 19:21:13.683 ERROR 37050 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in org.ws.web.db.DBOperation required a bean of type 'org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate' that could not be found.
    - Bean method 'namedParameterJdbcTemplate' not loaded because @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans


Action:

Consider revisiting the conditions above or defining a bean of type 'org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate' in your configuration.

这已经有一段时间了,所以我想谈谈如何理解这个问题并解决它。问题是NamedParameterJdbcTemplate并没有在DataSource中标记,它是Spring如何提取数据库的固定模板。参考检查它已经有一段时间了,所以我想评论一下如何理解这个问题并解决它。问题是NamedParameterJdbcTemplate并没有在DataSource中标记,它是Spring如何提取数据库的固定模板。参考退房
    Exception encountered during context initialization - cancelling refresh attempt: org.spr
ingframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'controller': Unsatisfied dependency expressed through field 'dbServices'; nested exception is org.sp
ringframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'DBServiesImplementation' defined in file [/Users/a/dev/challenge/challenge/bin/org/ws/web
/db/services/DBServiesImplementation.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyExce
ption: Error creating bean with name 'DBOperation' defined in file [/Users/a/dev/challenge/challenge/bin/org/ws/web/db/DBOperation.class]: Unsatisfied dependency expressed through 
constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.jdbc.core.namedparam.NamedParame
terJdbcTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2017-04-30 19:21:13.571  WARN 37050 --- [  restartedMain] o.s.boot.SpringApplication               : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defi
ned in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Initialization of bean failed; nested exception is org.springfra
mework.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' av
ailable)
2017-04-30 19:21:13.683 ERROR 37050 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in org.ws.web.db.DBOperation required a bean of type 'org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate' that could not be found.
    - Bean method 'namedParameterJdbcTemplate' not loaded because @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans


Action:

Consider revisiting the conditions above or defining a bean of type 'org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate' in your configuration.