I'm trying to configure Spring with Apache CXF using java config (no XML config) and wanted to know how to register JAXWS endpoints using spring java config. For example, what would be the 'java config' equivalent for the XML config below?
<jaxws:endpoint id="reportService" implementor="#reportServ" address="/reportService"/>
Kind regards,
Zahanghir
The 'Java-config' equivalent of your XML configuration is something like :
#Configuration
public class CXFConfiguration {
#Autowired
private ReportService reportServ;
#Bean
public Endpoint endpoint() {
Endpoint endpoint = new EndpointImpl(reportServ);
endpoint.publish("/reportService");
return endpoint;
}
}
I hope this can help you ^^.
Unfortunately, from what I can tell KevinHol's answer doesn't actually work. A working answer can be found at the sister thread (Apache CXF + Spring Java config (no XML)).
Related
I have a spring boot app that I upgraded from v2.2.x to now be v2.4.3.
I saw in their documentation that there is a new actuator endpoint of /startup, however it does not exist when I start my app.
There is no special requirement according to their documentation here
I am using spring-boot-admin-starter-client v2.4.3 which provides spring-boot-actuator v2.4.3, and i even have management.endpoint.startup.enabled=true in my application.properties file.
Has anyone else used this version of spring boot and gotten this actuator enpoint to work?
You need to tweak startup configuration:
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(DemoApplication.class);
app.setApplicationStartup(new BufferingApplicationStartup(1000));
app.run(args);
}
}
In application.properties:
management.endpoints.web.exposure.include=startup
If you want to visualize startup events check out this tool I made some months ago https://spring-boot-startup-analyzer.netlify.app/ (look at the configuration instructions as you need to enable CORS on this endpoint)
May be you are using BootstrapApplicationListener which build the application context again but ignores the previous applicationStartup, so it sets the default, this is a bug in spring-cloud-context:3.0.0
The OpenApi documentation says that it supports micrometer. How does the integration works? I could not find anything except this little documentation.
I have a FeignClient in a spring boot application
#FeignClient(name = "SomeService", url = "xxx", configuration = FeignConfiguration.class)
public interface SomeService {
#GET
#Path("/something")
Something getSomething();
}
with the configuration
public class FeignConfiguration {
#Bean
public Capability capability() {
return new MicrometerCapability();
}
}
and the micrometer integration as a dependency
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-micrometer</artifactId>
<version>10.12</version>
</dependency>
The code makes a call but I could not find any new metrics via the actuator overview, expecting some general information about my HTTP requests. What part is missing?
Update
I added the support for this to spring-cloud-openfeign. After the next release (2020.0.2), if micrometer is set-up, the only thing you need to do is putting feign-micrometer onto your classpath.
Old answer
I'm not sure if you do but I recommend to use spring-cloud-openfeign which autoconfigures Feign components for you. Unfortunately, it seems it does not autoconfigure Capability (that's one reason why your solution does not work) so you need to do it manually, please see the docs how to do it.
I was able to make this work combining the examples in the OpenFeign and Spring Cloud OpenFeign docs:
#Import(FeignClientsConfiguration.class)
class FooController {
private final FooClient fooClient;
public FooController(Decoder decoder, Encoder encoder, Contract contract, MeterRegistry meterRegistry) {
this.fooClient = Feign.builder()
.encoder(encoder)
.decoder(decoder)
.contract(contract)
.addCapability(new MicrometerCapability(meterRegistry))
.target(FooClient.class, "https://PROD-SVC");
}
}
What I did:
Used spring-cloud-openfeign
Added feign-micrometer (see feign-bom)
Created the client in the way you can see above
Importing FeignClientsConfiguration and passing MeterRegistry to MicrometerCapability are vital
After these, and calling the client, I had new metrics:
feign.Client
feign.Feign
feign.codec.Decoder
feign.codec.Decoder.response_size
I have a Spring Boot (2.1.5) application which uses the SecurityFilterAutoConfiguration feature. During registration of DelegatingFilterProxyRegistrationBean only REQUEST, ASYNC, ERROR DispatcherTypes are set. But I need FORWARD and INCLUDE as well.
The property security.filter-dispatcher-types from Spring Boot 1.x no longer works.
I can work around the problem by "overwriting" the DelegatingFilterProxyRegistrationBean as follows:
#Bean
#ConditionalOnBean(name = DEFAULT_FILTER_NAME)
#Primary
public DelegatingFilterProxyRegistrationBean customSecurityFilterChainRegistration(SecurityProperties securityProperties) {
DelegatingFilterProxyRegistrationBean registration = new DelegatingFilterProxyRegistrationBean(DEFAULT_FILTER_NAME);
registration.setOrder(securityProperties.getFilter().getOrder());
registration.setDispatcherTypes(allOf(DispatcherType.class));
return registration;
}
But that doesn't seem like a very elegant solution to me.
Is there a way to configure this for Spring Boot 2.1.x explicit?
You have to use spring.security.filter.dispatcher-types, see Spring Boot 2.0 Configuration Changelog.
How to use propeties in application.properties in SpringBoot 2.0.0.M7 App?
I have foloowed thedocumentation, but I dont know if I need to use OAuth2ClientProperties excplicitly
One more thing, the documentation doesn't according wih the autocompletion about
syntax parameter
my application.properies :
spring.security.oauth2.client.provider.verimi.authorization-uri=https://verimi.com/dipp/api/oauth/authorize
spring.security.oauth2.client.provid
spring.security.oauth2.client.registration.verimi.scope=login
spring.security.oauth2.client.registration.verimi.authorization-grant-typeer.verimi.tokenUri=https://verimi.com/dipp/api/oauth/token
spring.security.oauth2.client.registration.verimi.client-id=dipp
spring.security.oauth2.client.registration.verimi.clientSecret=G|41|0an18ZIs_w
spring.security.oauth2.client.registration.verimi.provider=verimi=authorization_code
OAuthConfig :
#Configuration
#EnableOAuth2Client
class OAuth2Config {
// What do I need to add ?
#Bean
fun oauth2RestTemplate(oauth2ClientContext: OAuth2ClientContext,
details: OAuth2ProtectedResourceDetails): :/* <--Error here : not bean found*/ OAuth2RestTemplate = OAuth2RestTemplate(details, oauth2ClientContext)
}
THX
Verimi does not use plain OAuth2 but OpenID Connect which uses OAuth2 as authorization protocol. A few days ago I managed to make the official Verimi Spring Boot sample work. If this might help you I have pushed it in Github.
we are in the process of converting current spring project into spring boot and at the same time converting all spring beans from xml to java config based.
i am stuck converting camel xml configuration into java based config.
currently we are specified camel config , routes and endpoints , one example as below
<camel:camelContext id="camelClient">
<camel:template id="camelTemplate"/>
</camel:camelContext>
<template id="camelTemplate"/>
here are couple of endpoints
<endpoint id="archiveUserQueue"
uri="swiftmq:${hk.jms.archive.queue.name}?concurrentConsumers=${hk.jms.archive.queue.consumers}"/>
<endpoint id="directSmsNotification" uri="direct:sendSMS"/>
one of the routes defined
<route>
<from ref="directSmsNotification"/>
<to uri="bean:messengerService?method=sendSmsMessage"/>
</route>
in java code we access the end point as below
smsEndpoint = _camelContext.getEndpoint("directSmsNotification");
how can we convert the camel config from xml to java based config.
i have followed instructions specified at http://camel.apache.org/spring-java-config.html but it was too hard to understand as i am not familiar with Camel.
You can mix and match Spring Java config with Apache Camel XML config. I question why you're doing this conversion in the first place.
That said, if you look at the camel docs you'll see there's an example for working with RouteBuilder.
You could also look at the sample spring-boot application. Here's a modified RouteBuilder from that example:
#Component
public class MySpringBootRouter extends RouteBuilder {
#Override
public void configure() {
Context context = getContext();
MyEndpoint ep = context.getEndpoint("someURI", MyEndpoint.class);
from(ep)
.transform().simple("ref:myBean")
.to("log:out");
}
}
Update: I modified the snippet to show getting an Endpoint directly. You can get more info in the Camel docs. I'm not sure how common this approach is. Back when I was using Camel regularly the endpoints were configured declaratively through their URI values. I don't think I ever explicitly defined an endpoint in my Camel XML or Java code. I'm sure there are use cases for it but it might be simpler for you to configure just by URI.