spring boot建立和資料庫關聯模組詳解
阿新 • • 發佈:2020-10-07
建立步驟
1.匯入依賴
2.配置檔案
3.建立啟動類
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.建立啟動類
@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建立和資料庫關聯模組的文章就介紹到這了,更多相關springboot建立資料庫關聯模組內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!