Introduction
In my previous I setup client certification authentication with RestClient https://magnus-k-karlsson.blogspot.com/2026/04/writing-mtlstwo-way-sslclient.html
Here I will use new Spring Boot 4 Rest Client: HTTP Service Clients
Configuration
The configuration of the RestClient is the same.
Java Interface
package se.magnuskkarlsson.clientcert;
import org.springframework.web.service.annotation.GetExchange;
public interface HelloService {
@GetExchange("/hello")
public String hello();
}
Use It
@Autowired
RestClient restClient;
private HelloService service;
// https://docs.spring.io/spring-framework/reference/integration/rest-clients.html#rest-http-service-client
@BeforeEach
void setUp() throws Exception {
// Using RestClient...
RestClientAdapter adapter = RestClientAdapter.create(restClient);
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
service = factory.createClient(HelloService.class);
}
@Test
void hello() throws Exception {
System.out.println(service.hello());
}
No comments:
Post a Comment