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

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

注釋@Autowired 出現(xiàn)問題。如何決定?

注釋@Autowired 出現(xiàn)問題。如何決定?

交互式愛情 2024-01-17 16:39:55
有一段代碼:package com.example.sweater3.domain;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;@Entitypublic class Message {    @Id    @GeneratedValue(strategy=GenerationType.AUTO)    private Integer id;    private String text;    private String tag;    public Message() {    }    public Message(String text, String tag) {        this.text = text;        this.tag = tag;    }    public void setText(String text) {        this.text = text;    }    public String getText() {        return text;    }    public Integer getId() {        return id;    }    public void setId(Integer id) {        this.id = id;    }    public String getTag() {        return tag;    }    public void setTag(String tag) {        this.tag = tag;    }}_package com.example.sweater3.repos;import com.example.sweater3.domain.Message;import org.springframework.data.repository.CrudRepository;import org.springframework.stereotype.Repository;import java.util.List;@Repositorypublic interface MessageRepo extends CrudRepository<Message, Long> {    List<Message> findByTag(String tag);}__package com.example.sweater3;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class Application {    public static void main(String[] args) {        SpringApplication.run(Application.class, args);    }}__package com.example.sweater3;import com.example.sweater3.repos.MessageRepo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;@Controllerpublic class GreetingController {    @Autowired    private MessageRepo messageRepo;}
查看完整描述

1 回答

?
紅顏莎娜

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

您必須在應(yīng)用程序中啟用存儲(chǔ)庫:


@SpringBootApplication

@EnableJpaRepositories


public class Application {

    public static void main(String[] args) {

        SpringApplication.run(Application.class, args);

    }

}

另請(qǐng)確保添加:


<dependency>

     <groupId>org.springframework.boot</groupId>

     <artifactId>spring-boot-starter-data-jpa</artifactId>       

</dependency>

更新:您必須配置數(shù)據(jù)庫連接和驅(qū)動(dòng)程序。H2 示例(在內(nèi)存數(shù)據(jù)庫中)


添加新的依賴項(xiàng):


<dependency>

     <groupId>com.h2database</groupId>

     <artifactId>h2</artifactId>

     <scope>runtime</scope>

</dependency>

在 application.properties 中添加:


spring.datasource.url=jdbc:h2:mem:testdb

spring.datasource.driverClassName=org.h2.Driver

spring.datasource.username=root

spring.datasource.password=root

spring.jpa.database-platform=org.hibernate.dialect.H2Dialect


查看完整回答
反對(duì) 回復(fù) 2024-01-17
  • 1 回答
  • 0 關(guān)注
  • 163 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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