我在我的 github 帐户中描述了我的数据库连接,但我无法从 github 获取数据库连接。它显示错误
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8288 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: no further information
应用程序.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/order-service
username: root
password:
application:
name: ORDER-SERVICE
eureka:
instance:
instance-id: ${spring.application.name}:${random.uuid}
server:
port: 0
引导程序.yml
spring:
cloud:
loabalancer:
ribbon:
enabbled: false
config:
uri: http://localhost:8888
vault:
host: localhost
port: 8288
scheme: http
authentication: TOKEN
token: s.9c6dLnEkGyp17hhibb9iNTss
application-name: order-service
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
订单.kt
package com.main.orderservice.model
import javax.persistence.*
@Entity
@Table(name = "t_order")
data class Order(
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
val id:Long=-1,
var orderNumber:String?="",
@OneToMany(cascade = [CascadeType.ALL])
var orderList: MutableList<OrderLineItem>?=null
)
订单项.kt
package com.main.orderservice.model
import java.math.BigDecimal
import javax.persistence.*
@Entity
@Table(name = "order_line_item")
data class OrderLineItem(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val odId:Long?=null,
val skuCode:String="",
val price:BigDecimal?=null,
val quantity:Int?=null,
)
orderrepository.kt
package com.main.orderservice.repository
import com.main.orderservice.model.Order
import org.springframework.data.jpa.repository.JpaRepository
in
接口 OrderRepository : JpaRepository<Order,Long> { }
订单控制器.kt
package com.main.orderservice.controller
import com.main.orderservice.client.InventoryClient
import com.main.orderservice.data.OrderDto
import com.main.orderservice.model.Order
import com.main.orderservice.repository.OrderRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.util.*
@RestController
@RequestMapping("/api/order")
class OrderController {
@Autowired
private lateinit var orderRepository: OrderRepository
@Autowired
private lateinit var inventoryClient: InventoryClient
@PostMapping
fun placeOrder(@RequestBody orderDto: OrderDto):String{
val allProductInStock:Boolean= orderDto.orderLineItemList .stream()
.allMatch { orderList -> inventoryClient.checkStatus(orderList.skuCode)}
return if (allProductInStock){
val order:Order=Order()
order.orderList= orderDto.orderLineItemList
order.orderNumber= UUID.randomUUID().toString()
orderRepository.save(order)
"Order placed successful"
}else{
"Order Replaced failed"
}
}
}
RestContig.kt
package com.main.orderservice.config
import feign.RequestInterceptor
import feign.RequestTemplate
import org.springframework.beans.factory.BeanFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
@Configuration
class RestConfig {
@Autowired
private lateinit var beanFactory: BeanFactory
@Bean
fun requestTokenBearerInterceptor(): RequestInterceptor? {
return RequestInterceptor { requestTemplate: RequestTemplate ->
val token: JwtAuthenticationToken = SecurityContextHolder.getContext()
.authentication as JwtAuthenticationToken
requestTemplate.header("Authorization", "Bearer " + token.token.tokenValue)
}
}
}
订单服务.yml
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
jpa:
database-platform: org.hibernate.dialect.MySQL5Dialect
show-sql: true
hibernate:
ddl-auto: update
我在我的 gitHub 帐户中定义的这个 Order-service.yml 但我无法获取数据库的连接这是完整的错误
Caused by: java.net.ConnectException: Connection refused: no further information
at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:660) ~[na:na]
at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:549) ~[na:na]
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:648) ~[na:na]
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75) ~[httpclient-4.5.13.jar:4.5.13]
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ~[httpclient-4.5.13.jar:4.5.13]
... 50 common frames omitted