spring boot創(chuàng)建和數(shù)據(jù)庫關聯(liá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);
}
}
總結
到此這篇關于spring boot創(chuàng)建和數(shù)據(jù)庫關聯(lián)模塊的文章就介紹到這了,更多相關springboot創(chuàng)建數(shù)據(jù)庫關聯(lián)模塊內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
rabbitmq basicReject/basicNack/basicRecover的區(qū)別及說明
這篇文章主要介紹了rabbitmq basicReject/basicNack/basicRecover的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01
Springboot升級到2.7.2結合nacos遇到的坑及解決
這篇文章主要介紹了Springboot升級到2.7.2結合nacos遇到的坑及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06
ConditionalOnProperty注解的作用和使用方式
在SpringBoot項目開發(fā)中,@ConditionalOnProperty注解允許根據(jù)配置文件中的屬性值來控制配置類是否生效,該注解通過屬性name和havingValue來判斷配置是否注入,如果application.properties中的對應屬性值為空或不匹配havingValue設定值2024-09-09
mybatis-plus動態(tài)表名的實現(xiàn)示例
這篇文章主要介紹了mybatis-plus動態(tài)表名的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-04-04
SpringBoot響應處理之以Json數(shù)據(jù)返回的實現(xiàn)方法
這篇文章主要介紹了SpringBoot整合Web開發(fā)其中Json數(shù)據(jù)返回的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-09-09

