欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

記一次Springboot搭建過程-創(chuàng)新互聯(lián)

遇到的問題如下:

仁壽ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!

1.Spring Boot正常啟動(dòng)后,訪問Controller報(bào)404
問題描述:

spring boot正常啟動(dòng),通過 http://localhost:8000/hello/first 訪問,一直報(bào)404

原因:

在搭建完項(xiàng)目之后,Application類是放在com.example.hello的包下面,而Controller類是放置在com.example.controller的包下面,導(dǎo)致spring boot無法掃描controller包下的內(nèi)容(默認(rèn)掃Application類對應(yīng)的包下的內(nèi)容)
解決措施:

方法1:將controller包下的類移動(dòng)到hello包下

方法2:在啟動(dòng)上方添加@ComponentScan注解,此注解為指定掃描路徑,例如:@ComponentScan(basePackages = {"com.example.controller"})

package com.example.hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = {"com.example.controller"})
public class HelloApplication {

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

}

2.無法注入繼承JpaRepository的接口
問題描述:

如下代碼該接口在繼承JpaRepository后,在controller類中通過@Autowired注入時(shí),工程一直無法啟動(dòng),并報(bào)
Parameter 0 of constructor in com.example.controller.ReadingListController required a bean of type 'com.example.model.ReadingListRepository' that could not be found.

記一次Spring boot搭建過程

package com.example.model;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ReadingListRepository extends JpaRepository<Book, Long> {

    List<Book> findByReader(String reader);
}
package com.example.controller;

import com.example.model.Book;
import com.example.model.ReadingListRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
@RequestMapping("/readingList")
public class ReadingListController {

    ReadingListRepository readingListRepository;

    @Autowired
    public ReadingListController(ReadingListRepository readingListRepository) {
        this.readingListRepository = readingListRepository;
    }

    @RequestMapping(value = "/{reader}", method = RequestMethod.GET)
    public String readersBooks(@PathVariable("reader") String reader, Model model) {
        List<Book> readingList = readingListRepository.findByReader(reader);
        if (readingList != null) {
            model.addAttribute("books", readingList);
        }
        return "readingList";
    }

    @RequestMapping(value = "/{reader}", method = RequestMethod.POST)
    public String addToReadingList(@PathVariable("reader") String reader, Book book) {
        book.setReader(reader);
        readingListRepository.save(book);
        return "redirect:/readingList/{reader}";
    }
}

原因:

Springboot未能正常將其掃描并沒注入到容器中。而且一般在使用Springboot的初始框架中,啟動(dòng)類位置于所有Service,Entity,Controller或者其它類的最上層的話,這個(gè)問題很少會(huì)出現(xiàn)。

解決措施:

方案一、把 @SpringBootApplication 注解的 SpringBoot 入口類移到上層 root 包中,使?JpaRepository 子接口位于 root 包及其子包中。

方案二、在 SpringBoot?入口類上添加

(1) @ComponentScan(basePackages = "xxx.xxx.xxx"):掃描 @Controller、@Service 注解;
????(2) @EnableJpaRepositories(basePackages = "xxx.xxx.xxx"):掃描 @Repository 注解;
????(3) @EntityScan(basePackages =?"xxx.xxx.xxx"):掃描 @Entity 注解;

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

本文題目:記一次Springboot搭建過程-創(chuàng)新互聯(lián)
瀏覽路徑:http://aaarwkj.com/article34/ccjhpe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、電子商務(wù)網(wǎng)站建設(shè)、外貿(mào)建站營銷型網(wǎng)站建設(shè)、域名注冊

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
日本加勒比在线播放一区| 国产三级精品三级在线专区1 | 日本女优高清不卡一二三四区| 久久久精品在线免费视频| 日本不卡不码高清免费| 亚洲精品成人久久网| 天天操天天日天天射夜夜爽| 亚洲国产精品自拍第一页| 国产亚洲一区二区精品| 欧美亚洲伊人久久综合| 日韩人妻一区中文字幕| 久久国产精品亚洲欧美| av免费在线观看大全| 国产伦奸在线播放免费| 国产激情片午夜福利| 国产乱来视频在线观看| 亚洲av毛片一区二区| 七月丁香色婷婷婷基地| 人妻系列日本在线播放| 日本成人午夜福利在线观看| 日本在线观看免费高清| 国语自产精品视频在线不卡| 久久婷婷欧美激情综合| 国产精品一区久久91| 日本国内一区二区三区四区视频 | 69人妻一区二区三区蜜桃| 亚洲人妻av一区二区三区| 国产男女做爰在线视频| 亚洲国产精品久久久精品| 亚洲av在线观看午夜| 激情亚洲不卡一区二区| av岛国不卡一区二区在线观看| 国产高清av免费观看| 日韩av黄色大片在线播看| 亚洲夫妻性生活免费视频| 久久国产麻豆精品电影| 精品人妻一区二区av| 日本美女阴部毛茸茸视频| 亚洲日本不卡在线一区二区| 国产成人福利视频在线观看| 开心激情欧美一区二区|