datdatyul
Active Coder
I have a problem about solving JwtGrantedAuthoritiesConverter in order service after defining preauthorize annotation in some methods of Order Controller.
After I wrote the test shown below, I tried to run it but I got this issue shown below as well.
I also shared my repo as a link.
How can I fix it?
Here is the test method shown below
Here is the application.yaml underneath test folder
Here is the error shown below.
Then I added spring-security-oauth2-resource-server dependency in order service, I got this issue show below.
How can I fix it?
After I wrote the test shown below, I tried to run it but I got this issue shown below as well.
I also shared my repo as a link.
How can I fix it?
Here is the test method shown below
Code:
@Test
public void test_WhenPlaceOrder_DoPayment_Success() throws Exception {
//First Place Order
// Get Order by Order Id from Db and check
//Check Output
OrderRequest orderRequest = getMockOrderRequest();
MvcResult mvcResult
= mockMvc.perform(MockMvcRequestBuilders.post("/order/placeOrder")
.with(jwt().authorities(new SimpleGrantedAuthority("USER")))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(orderRequest))
).andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String orderId = mvcResult.getResponse().getContentAsString();
Optional<Order> order = orderRepository.findById(Long.valueOf(orderId));
assertTrue(order.isPresent());
Order o = order.get();
assertEquals(Long.parseLong(orderId), o.getId());
assertEquals("PLACED", o.getOrderStatus());
assertEquals(orderRequest.getTotalAmount(), o.getAmount());
assertEquals(orderRequest.getQuantity(), o.getQuantity());
}
Here is the application.yaml underneath test folder
Code:
server:
port: 8082
spring:
datasource:
url: jdbc:h2:mem:order
username: sa
password: password
driverClassName: org.h2.Driver
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
application:
name: ORDER-SERVICE
config:
import: configserver:http://localhost:9296
Here is the error shown below.
Code:
java.lang.NoClassDefFoundError: org/springframework/security/oauth2/server/resource/authentication/JwtGrantedAuthoritiesConverter
Caused by: java.lang.ClassNotFoundException: org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter
Then I added spring-security-oauth2-resource-server dependency in order service, I got this issue show below.
Code:
Caused by: java.lang.ClassNotFoundException: org.springframework.security.oauth2.jwt.Jwt$Builder
How can I fix it?