第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

沒有類型為“org.springframework.jdbc.core.JdbcTemplate”

沒有類型為“org.springframework.jdbc.core.JdbcTemplate”

哆啦的時(shí)光機(jī) 2023-07-13 14:14:28
我正在https://developer.ibm.com/tutorials/spring-with-db2-via-jdbc/上運(yùn)行tutorial.example, 但無法讓它工作,我不斷收到以下錯(cuò)誤,并且不確定如何修復(fù)。沒有“org.springframework.jdbc.core.JdbcTemplate”類型的合格 bean 可用:預(yù)計(jì)至少有 1 個(gè)有資格作為自動(dòng)裝配候選者的 bean。依賴注釋:{@org.springframework.beans.factory.annotation.Autowired(required=true)}'教程中沒有提到與設(shè)置 bean 相關(guān)的內(nèi)容,所以我不確定我是否應(yīng)該中斷它來修復(fù)它,或者我只是犯了一個(gè)錯(cuò)誤。我的應(yīng)用程序類 -@SpringBootApplicationpublic class SBApplication {    public static void main(String[] args) {        SpringApplication.run(SBApplication.class, args);    } }休息控制器示例 -package application.rest.v1;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import org.springframework.http.HttpStatus;import org.springframework.http.ResponseEntity;import org.springframework.web.bind.annotation.ResponseBody;import java.util.ArrayList;import java.util.List;import main.java.application.jdbc.*;@RestControllerpublic class Example {    @Autowired    JdbcTemplate jdbcTemplate;    @RequestMapping("test")    public @ResponseBody ResponseEntity<String> example() {        List<String> list = new ArrayList<>();        list.add("Table data...");        jdbcTemplate.query(                "SELECT * FROM things", new Object[]{},                (rs,rowNum) -> new Things(rs.getLong("id"), rs.getString("name")))                .forEach(thing -> list.add(thing.toString()));        return new ResponseEntity<String>(list.toString(), HttpStatus.OK);    }}application.properties -spring.datasource.url=jdbc:imdb://xxxx.xxx.xxxx/xxxxspring.datasource.username=xxxxxxxspring.datasource.password=xxxxspring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration另外,我沒有連接到教程中建議的 DB2 實(shí)例,而是連接到我自己的實(shí)例。
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊

我相信您缺少應(yīng)該JdbcTemplate在配置中配置的部分。當(dāng)您使用 時(shí),您可以通過類上的注釋spring boot來實(shí)現(xiàn)它。@Configuration您的典型配置如下所示


@Configuration

public class WebAppConfig {


    @Bean(name = "appDataSource")

    @Primary

    @ConfigurationProperties(prefix = "spring.datasource")

    public DataSource dataSource() {

        return DataSourceBuilder.create().build();

    }


    @Bean(name = "applicationJdbcTemplate")

    public JdbcTemplate applicationDataConnection(){

        return new JdbcTemplate(dataSource());

    }

}


查看完整回答
反對 回復(fù) 2023-07-13
  • 1 回答
  • 0 關(guān)注
  • 193 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號