Spring boot 2 with apache camel application start error - spring

I have a requirement where I need to listen to a active mq and call rest post api for the data I have recieved as body, for this I have created simple spring boot 2.x application and trying to start a router, but application is failing to start.
My understanding about registering a Router is to anottate a class with #Component and it should implement camel RouteBuilder
#Component
public class Router extends RouteBuilder{
#Override
public void configure() throws Exception {
from("timer:foo").to("log:bar");
}
}
JDK 1.8
Spring boot version 2.2.6.RELEASE
Camel version 2.24.0
Pom xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.24.0</version>
</dependency>
</dependencies>
The error I am getting is
Caused by: java.lang.ClassNotFoundException: org.apache.camel.spring.spi.XmlCamelContextConfigurer
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]

Try removing the camel-spring dependency. This should be pulled transitively through camel-spring-boot-starter.
The error message could be a problem with different Camel versions. For example if ${camel.version} in your POM is not defined or not equal to 2.24.0 you could have mixed Camel versions for camel-spring and camel-core.

If there will be any resource can't able to downloaded in your system so for this you have to uninstall the application and delete all the files from c/program-file/ and then install it again. Hope it will help you out from this issue.

Related

camel springboot and hawtio integration

I am working on integrating the camel springboot component with hawtio. I can't see the camel tab in the hawtio UI. I am using below dependencies of springboot camel and hawtio
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-springboot</artifactId>
<version>2.10.1</version>
</dependency>
This the sample route i configured, route is working as expected
#Component
public class SampleRoute extends org.apache.camel.builder.RouteBuilder{
#Override
public void configure() throws Exception {
from("kafka:test123?brokers=localhost:9092&allowManualCommit=true&autoCommitEnable=false&breakOnFirstError=true&maxPollRecords=1&synchronous=true")
.process(exchange -> {
exchange.getIn().setBody("test1234");
}).to("stream:out");
}
}
After reading many articles , i added below set of properties and it seems to have any effect.
management.endpoints.web.exposure.include=hawtio,jolokia
management.endpoints.jolokia.sensitive=false
endpoints.jolokia.sensitive = false
hawtio.authenticationEnabled=false
spring.jmx.enabled=true
camel.springboot.endpoint-runtime-statistics-enabled=true
management.endpoint.camelroutes.enabled=true
management.info.camel.enabled=true
management.endpoint.camelroutes.enabled=true
management.endpoint.camelroutes.read-only=true
camel.springboot.jmx-enabled=true
One of the solution worked for me is by downgrading to camel 2.X , but no luck with camel 3.X
I got it working, following the link as suggested. I had to remove the conflicting dependencies and adding below dependency worked.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-management</artifactId>
<version>3.2.0</version>
</dependency>

ElasticSearchHighLevelClient springboot Autoconfiguration not working

I am trying to autoconfigure elasticsearch high-level rest client using this documentation
https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-elasticsearch
I added the following properties to my application.properties:
spring.elasticsearch.rest.uris=https://hostname.com
spring.elasticsearch.rest.read-timeout=10s
spring.elasticsearch.rest.username= user
spring.elasticsearch.rest.password= password
I added these dependencies in my pom.xml
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
and a property
<elasticsearch.version>7.2.1</elasticsearch.version>
In my application I did this
#Configuration
#EnableAutoConfiguration
#SpringBootApplication
#ComponentScan
public class MainClass {
public static void main(String[] args) {
SpringApplication.run(MainClass.class, args);
}
}
But when I try to use the HighLevelClient it gives me NullPointerException
#Autowired
private RestHighLevelClient client;
Am I missing something?
You should add the stacktrace for the NullPointerException.
You did not write which versions you use (Spring Boot, Spring Data Elasticsearch). But the current Spring Boot 2.2.2 targets Spring Data Elasticsearch 3.2.x which uses Elasticsearch 6.8.5. So this won't work with an Elasticsearch 7 cluster. Support for Elasticsearch 7 is coming with the next version (Spring Data Elasticsearch 4.0)
I hope you are using spring-boot-autoconfigure dependency because RestHighLevelClient bean is initialized by this library based on the presence of RestHighLevelClient in the classpath. Check the dependency tree for the presence of spring-boot-autoconfigure.

incompatible version of apache.camel with Spring.Boot v2.0

Anyone could englighten me which org.apache.camel version I should use with the Spring boot version 2.0.0 .RELEASE.
When I used newer versions of apache.camel such like 2.21.0 , I come across with RelaxedPropertyResolved error. I read the forums and I was told to downgrade the version of Spring Boot which I cant. I have to use sprint.boot.version 2.0.0 with a new apache.camel.version without making changes at my java code ?
Do you think is it possible?
These are my dependecies for camel.version and spring.boot.version. Please let me know if you need anything more.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bom</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>import</scope>
<version>2.21.0
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
<version>2.21.0</version>
</dependency>
Error :
at com.project.eventrouter.Application.main(Application.java:26)
Caused by: java.lang.IllegalStateException: Could not evaluate condition on
org.apache.camel.spring.boot.security.CamelSSLAutoConfiguration due to
org/springframework/boot/bind/RelaxedPropertyResolver not found. Make sure
your own configuration does not rely on that class. This can also happen if
you are #ComponentScanning a springframework package (e.g. if you put a
#ComponentScan in the default package by mistake)
org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:55)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:109)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:217)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:606)
... 13 common frames omitted
Camel 2.21.x or older is Spring Boot 1.5.x
Camel 2.22.x is Spring Boot 2.0.x only
Camel 2.23.x is Spring Boot 2.1.x (and potentially also Spring Boot 2.0.x)

using embedded amqp swith spring boot and camel

I want to integration test a custom camel component and therefor need an embedded/in memory messanging I can easily use to test from/to endpoints.
I am hoping that I can achieve this via spring-boot-amqp-starter.
I used this example for a start, which has the dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
and the config:
spring:
activemq:
broker-url: vm://embedded?broker.persistent=false,useShutdownHook=false
// ...
This is working, when I use regular Listener annotations in spring, I have a sender using the template and a consumer logging the messages.
Now I go one step further and use camel, but it does not recognize the vm:embedded broker but tries to connect to tcp://localhost, which is not running.
return new RouteBuilder() {
#Override
public void configure() throws Exception {
from("activemq:foo").to("log:sample");
from("timer:bar").setBody(constant("Hello from Camel")).to("activemq:foo");
}
};
How can I configure activemq-camel to use the embedded broker?
Update:
I use dependency management imports for spring-boot-dependencies (1.5.9)
and camel-spring-boot-dependencies (2.20.1).
This has been fixed in newer versions of activemq-camel when you use that with Spring Boot. Now the activemq-camel component will honor the spring boot configuration of the spring.activemq.* settings.

How to use the latest version of Vaadin4Spring EventBus framework with Maven?

I have a Spring Boot project with Vaadin, I would like to integrate the Vaadin4Spring EventBus framework:
https://github.com/peholmst/vaadin4spring/tree/master/spring-vaadin-eventbus
The author says:
Please note, that the Event Bus API changed in version 0.0.5
However, if I add the Maven dependency inside my pom.xml:
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>LATEST</version>
</dependency>
...
Maven downloads the 0.0.4.RELEASE version. I have tried to explicitly set the following versions:
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5</version>
</dependency>
...
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5.RELEASE</version>
</dependency>
...
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5-SNAPSHOT</version>
</dependency>
...
I also tried to set the entire Spring4Vaadin addon as a dependency:
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>LATEST</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5-SNAPSHOT</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5.RELEASE</version>
</dependency>
But neither of them worked.
Basically, I cannot do this:
#Autowired
EventBus.ApplicationEventBUs appEventBus;
#Autowired
EventBus.UIEventBus UIEventBus;
...
Because, as said in the README.md on GitHub:
Please note, that the Event Bus API changed in version 0.0.5. From now
on, you have to declare which event bus to inject by using a specific
interface (previously, everything was EventBus and you used an
annotation to specify which bus to get). The reasons for this change
were
So in the version 0.0.4.RELEASE (which Maven sees as LATEST), the inner interfaces ApplicationEventBus and UIEventBus are not defined.
So, how can I use the true latest version of the addon?
Putting the answer I put in the vaadin forums, over here as well:
Vaadin addons has a nice Event Bus implementation. Check https://github.com/peholmst/vaadin4spring/tree/master/samples/eventbus-sample
I have done this using a spring enabled (NOT spring boot) Vaadin application, but it might work without Spring as well I guess, Short steps:
1. Add the following dependency
<dependency>
<groupId>org.vaadin.spring.addons</groupId>
<artifactId>vaadin-spring-addon-eventbus</artifactId>
<version>0.0.7.RELEASE</version>
</dependency>
Import EventBusConfiguration.class into your Spring configuration (may not be required if Spring Boot is used with #EnableAutoConfiguration)
Wire in appropriate event bus (check doumentations for different types available), here I am using one that works per UI instance:
#Autowired
private EventBus.UIEventBus uiEventBus;
Publish event as required, eg:
uiEventBus.publish(this, new RefreshMainViewEvent(this, "Usage details updated"));
Subscribe to event in the other component class
#PostConstruct
public void afterPropertiesSet() {
uiEventBus.subscribe(this, false);
}
Add the action to be done on event (in the same class here) :
#EventBusListenerMethod
public void closeSymmUsageWindow(RefreshMainViewEvent event) {
logger.debug("Received {}", event);
//blah
}

Resources