spring boot創(chuàng)建和數(shù)據(jù)庫關(guān)聯(lián)模塊詳解
更新時間:2020年10月02日 10:53:33 作者:小小書童437
這篇文章主要給大家介紹了關(guān)于spring boot創(chuàng)建和數(shù)據(jù)庫關(guān)聯(lián)模塊的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
創(chuàng)建步驟
1.導入依賴
2.配置文件
3.創(chuàng)建啟動類
1.導入依賴
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <!--自定義公共模塊,可見公共模塊文章--> <dependency> <groupId>com.xx</groupId> <artifactId>common_db</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.xx</groupId> <artifactId>service_goods_api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>
2.配置文件
server: port: 9011 spring: application: name: goods datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://192.168.200.128:3306/goods?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC username: root password: root eureka: client: service-url: defaultZone: http://127.0.0.1:6868/eureka instance: prefer-ip-address: true feign: hystrix: enabled: true #hystrix 配置 hystrix: command: default: execution: timeout: #如果enabled設置為false,則請求超時交給ribbon控制 enabled: true isolation: strategy: SEMAPHORE
3.創(chuàng)建啟動類
@SpringBootApplication
@EnableEurekaClient
//@MapperScan是tk.mybatis.spring.annotation包下的,用于掃描Mapper接口*
@MapperScan(basePackages = {"com.goods.dao"})
public class GoodsApplication {
public static void main(String[] args) {
SpringApplication.run(GoodsApplication.class);
}
}
總結(jié)
到此這篇關(guān)于spring boot創(chuàng)建和數(shù)據(jù)庫關(guān)聯(lián)模塊的文章就介紹到這了,更多相關(guān)springboot創(chuàng)建數(shù)據(jù)庫關(guān)聯(lián)模塊內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
springcloud-gateway集成knife4j的示例詳解
這篇文章主要介紹了springcloud-gateway集成knife4j的示例詳解,本文結(jié)合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03
@FeignClient注解中屬性contextId的使用說明
這篇文章主要介紹了@FeignClient注解中屬性contextId的使用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06

