Apache CXF JAX-WS spring-boot starter very slow - performance

I'm working on a spring-boot application which has 100+ JAX-WS endpoints. I'm using apache CXF and the boot time performance is terrible. It takes more than 10 mins to publish 100 endpoints.
I tried to enable debug logs and see that cxf is creating a new JAXBContext instance for every endpoint. I tried to find material to configure single JAXBContext but none of the available material show properly how I can do it.
FYI: I'm using JavaFirst approach here.
Any suggestions to improve boot time performance are welcome.
Thanks,
Sriram

For JAX-WS please look at this existing question: Reuse CXF jaxb context between multiple services
Instead of declaring it using XML you can also add the bean for org.apache.cxf.jaxb.JAXBDataBinding using the #Bean annotation.
In case someone is looking for JAX-RS, this is handled differently. You need to add a bean for org.apache.cxf.jaxrs.provider.JAXBElementProvider and set singleJaxbContext to true as written in the docs: http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-SingleJAXBContextandextrauserclasses

Related

what does "spring-kafka without springboot" mean

I'm totally new to Kafka and terribly confused by this:
https://docs.spring.io/spring-kafka/reference/html/#with-java-configuration-no-spring-boot
I don't understand what that even means. What does "no spring boot mean" because that example sure as hell uses spring boot. I'm so confused....
EDIT
if I'm using SpringBoot and spring-kafka, should I have to manually create #Bean ConcurrentKafkaListenerContainerFactory as shown here. Most of the examples in the docs for setting up filtering / config / etc seem to use the "manual" configuration using #Bean. Is that "normal"? The docs are very confusing to me...especially this warning:
Spring for Apache Kafka is designed to be used in a Spring Application Context. For example, if you create the listener container yourself outside of a Spring context, not all functions will work unless you satisfy all of the …​Aware interfaces that the container implements.
It's referring to the autowired configuration, as compared to putting each property in the config via HashMap/Properties in-code.
Also, it does not use #SpringBootApplication or SpringApplication.run, it just calls a regular main method using a hard-coded Config class.
Spring boot contains the functionality of AutoConfiguration
What this means is that spring boot when discovers some specific jar dependencies it knows, in the project, it automatically configures them to work on a basic level. This does not exist in simple Spring project where even if you add the dependency you have to also provide the configuration as to how it should work in your application.
This is also happening here with dependencies of Kafka. Therefore the documentation explains what more you have to configure if you don't have spring-boot with auto-configuration to make kafka work in a spring project.
Another question asked in comment is what happens in case you want some complex custom configuration instead of the automatic configuration provided while you are in a spring-boot app.
As documented
Auto-configuration tries to be as intelligent as possible and will
back-away as you define more of your own configuration. You can always
manually exclude() any configuration that you never want to apply (use
excludeName() if you don't have access to them). You can also exclude
them via the spring.autoconfigure.exclude property.
So if you want to have some complex configuration which is not automatically provided by spring-boot through some other mechanism like a spring-boot specific application property, then you can make your own configuration with your custom bean and then either automatic configuration from spring-boot for that class will back of as spring does several intelligent checks during application context set up or you will have to exclude the class from auto configuration manually.
In that case you could probably take as an example reference of how to register manually your complex configurations in spring boot what is documented on how to be done in non spring boot app. doc

List of Spring Boot provided beans?

Is there a list of beans provided by Spring Boot and its different modules? For example, I only recently discovered that Spring Boot already provides a configurable Jackson ObjectMapper bean. I would have never known that if not for reading up on an unrelated issue I was dealing with. Now I'm working with Spring JMS and am afraid that I am reinventing the wheel because Spring Boot may already have what I need and I just don't know about it. How are these beans discovered? They don't seem to be cataloged in any Spring documentation.
I would recommend starting with the reference documentation. While it doesn't list every bean that may be auto-configured, it does have documentation describing each feature area that may be auto-configured. For example, there are sections on Jackson's ObjectMapper and on JMS.
Each starter that Spring Boot offers is also a good indication of what it can auto-configure. Each first-party starter is listed in the documentation.

spring-integration-kafka annotation support & example

Although new to spring, I'm usually able to get started with a spring projects fairly well with annotations only. The official examples uses xml without mentioning where they will be placed etc.
Is there any sample project on reading from a kafka topic? Preferably by using annotation to set the zk & kafka configuration properties.
Please, take a look to the Spring Integration Java DSL project and here is a KafkaTests to demonstrate how to be for your case.
Plus here you are Josh Long's article: https://spring.io/blog/2015/04/15/using-apache-kafka-for-integration-and-data-processing-pipelines-with-spring

Difference between Spring and Spring Boot

There are many people who advised me to use Spring Boot instead of Spring to develop REST web services.
I want to know what exactly the difference between the two is?
In short
Spring Boot reduces the need to write a lot of configuration and boilerplate code.
It has an opinionated view on Spring Platform and third-party libraries so you can get started with minimum effort.
Easy to create standalone applications with embedded Tomcat/Jetty/Undertow.
Provides metrics, health checks, and externalized configuration.
You can read more here http://projects.spring.io/spring-boot/
Unfortunately and I mean this out of personal frustration with Spring boot, I have yet to see any real quantified list, where the differences are explicitly outlined.
There is only qualifications such as the rubbish sentence "...opinionated view..." which are bandied about.
What is clear, is that SpringBoot has wrapped up groups of Spring annotations into its own set of annotations, implicitly.
Further obfuscating, and making the need for anyone starting out in SpringBoot to have to commit to memory what a particular SpringBoot annotation represents.
My reply therefore is of no quantifiable benefit to the original question, which is analogous to that of the SpringBoot authors.
Those behind Spring IMO deliberately set-out to obfuscate, which reflects the obtuseness of their JavaDoc and API's (see SpringBatch API's as an example, if you think I am flaming) that makes one wonder the value of their open-source ethos.
My quest for figuring out SpringBoot continues.
Update. 22-08-2022
Read this (https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.auto-configuration) and you will figure out for yourself what "opinionated" means.
There are over 140 Config classes that Springboot can use for this opinionated view, depending on what is on your classpath.
yes, on your classpath.
Finally and bizzarely, the annotation #SpringBootApplication is a configuration annotation as it includes it.
Go figure :=)
Basically, Spring Boot is an opinionated instance of a Spring application.
Spring Boot is a rapid application development platform. It uses various components of Spring, but has additional niceties like the ability to package your application as a runnable jar, which includes an embedded tomcat (or jetty) server. Additionally, Spring Boot contains a LOT of auto-configuration for you (the opinionated part), where it will pick and choose what to create based on what classes/beans are available or missing.
I would echo their sentiment that if you are going to use Spring I can't think of any reasons to do it without Spring Boot.
Spring Boot is opinionated view of Spring Framework projects.Let's analyse it through one program taken from Spring Boot Documentation.
#RestController
#EnableAutoConfiguration
public class Example {
#RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}
}
It's a very basic REST API and you need to add Spring-boot-starter-web in your POM.xml for the same. Since you have added starter-web dependency, the annotation
#EnableAutoConfiguration guesses that you want to develop a web application and sets up Spring accordingly.
Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added. For example, if HSQLDB is on your classpath, and you have not manually configured any database connection beans, then Spring Boot auto-configures an in-memory database.
It's opinionated like maven. Maven creates a project structure for you which it thinks is the general pattern of projects like it adds src/main/java folder or resource folder for you.
Spring boot helps in faster development. It has many starter projects that helps you get going quite faster. It also includes many non functional features like: embedded servers, security, metrics, health checks etc. In short, it makes, spring based application development easier with minimally invading code(Less configuration files, less no of annotations).
Reference: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-documentation-about
For developing common Spring applications or starting to learn Spring, I think using Spring Boot would be recommended. It considerably eases the job, is production ready and is rapidly being widely adopted.
Spring Boot is supposedly opinionated, i.e. it heavily advocates a certain style of rapid development, but it is designed well enough to accommodate exceptions to the rule, if you will. In short, it is a convention over configuration methodology that is willing to understand your need to break convention when warranted
For Spring Framework, you need to configure your project using XML configuration or Java configuration.
But for Spring Boot, these are preconfigured according to Spring team's view for rapid development. That is why Spring Boot is said to be an "opinionated view" of Spring Framework. It follows Convention over Configuration design paradigm.
Note: These configurations include view resolvers for MVC, transaction managers, way of locating container managed beans (Spring beans) and many more. And of course you can override any of these preconfigurations according to your need.
Spring Boot supports embedded servlet containers like Tomcat, Jetty or Undertow to create standalone applications, which Spring Framework doesn't.
Spring eliminate boilerplate code.
Spring-boot eliminates boilerplate configurations.
more

Spring 4 using Groovy setup

Spring 4.0 has improved support for Groovy e.g. using the GroovyBeanDefinitionReader.
What would be setup to to have a full Spring MVC application using Groovy?
E.g. using GroovyBeanDefinitionReader and AnnotationConfigWebApplicationContext together.
Anyone knows if there is a sample available or some pointers on a blog site?
You might want to check out spring boot, still in milestone release behind Spring 4 but they were really pushing its groovy support at spring eXchange.
Check out the bottom of this spring-boot guide
It's not quite the use of GroovyBeanDefinitionReader and AnnotationConfigWebApplicationContext you asked for, but I can't see why you couldn't do what you are after with the opinionated approach used by spring boot and the standard configuration annotations on groovy classes.
The git hub repository shows a number of annotated groovy examples
with ui.groovy for example, showing a configuration class for the WebMvcConfigurerAdapter defining a bean.
In your main method, do SpringApplication.run(new Object[]{JavaConfig.class, "beans.groovy"}, args), where JavaConfig contains your configurations in java (like #Configuration, #ComponentScan and etc., I generally find these things are easier using annotations) and beans.groovy just contain your spring beans DSL.
Assuming beans.groovy is on classpth (i.e. under src/main/resources)

Resources