What is difference between: CamelContext vs ExtendedCamelContext vs SpringCamelContext? - spring-boot

SpringBoot + ApacheCamel
I have problem with *CamelContext I got exception:
Cannot cast org.apache.camel.spring.SpringCamelContext to org.apache.camel.ExtendedCamelContext
during initialization some components.
parto of my configuration (pom.xml):
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
...
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.25.2</version>
</dependency>
...
Question: How to use these context / which one should be used ?
CamelContext aka DefaultCamelContext
ExtendedCamelContext
SpringCamelContext

Related

I want to extend WebSecurityConfigurerAdapter but it had been deprecated

I'm trying to code a website using spring boot(security, jpa, web...) and i'm following this tutorial.
And in the minute : 1:05:25 , he needs to extend the WebSecurityConfigurerAdapter, but it had been deprecated in the last spring boot versions, so he changes the version in his "pom.xml" from :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
To :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Then he saves all and updtaes the project. And when I do the same I get errors in my pom.xml file in the parent tag:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
with the error : Coul not read maven project ...
And I get an error in this dependancy :
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
The error is :
3.0.0+
The <dependency> element contains information about a dependency of the project.
Source: maven-4.0.0.xsd`
I also get this error in my console :
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
While in the video, he doesn't get errors at all.
So I would like to solve the problem by modifying something in my pom.xml and keeping that application.

Upgrading Spring Boot to 2.5.9 and getting FileNotFoundException: class path ...../boot/actuate/health/HealthAggregator.class] cannot be opened

I am getting a FileNotFoundException during Spring Boot initiation for org/springframework/boot/actuate/health/HealthAggregator.class. This seem related to https://github.com/spring-projects/spring-boot/issues/19860 but that was back in 2.2.
I have tried different versions of Spring Boot, 2.5.9 etc, different versions of Spring Cloud, etc.
Any thoughts on how I can resolved this?
Key parts of my POM
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
..
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-client-config</artifactId>
<version>2.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
The error:
is 2022-01-25 20:16:20 WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.xxxxx.vms.yyyyy]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/actuate/health/HealthAggregator.class] cannot be opened because it does not exist 2022-01-25 20:16:20 ERROR o.s.boot.SpringApplication - Application run failed

Problem extending Spring WebFlux application with reactive DB client: conflicting Maven dependencies?

I have a small working Spring WebFlux app made basing on this code:
https://github.com/chang-chao/spring-webflux-reactive-jdbc-sample
As far as I've understood this is some kind of mix between purely reactive programming and usual blocking relational databases.
Now I have a task to add reactive DB client to my app. I stared with this guide:
https://spring.io/guides/gs/accessing-data-r2dbc/
But as soon as I added following dependencies to my pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-h2</artifactId>
<version>0.8.4.RELEASE</version>
<scope>runtime</scope>
</dependency>
my WORKING app failed to start saying it couldn't find autowired repository bean. This error disappeared as soon as I've removed two dependencies above.
Initial full pom.xml of WORKING app:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.freelance</groupId>
<artifactId>studentlist</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>student-list</name>
<description>Spring WebFlux application for managing students</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.3.4.RELEASE</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.3.10.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I suppose some dependencies are conflicting with each other. Is there a way to actually use these dependencies with all my other dependencies so I'll be able to follow that guide?
I don't know if app's Java code is needed for this question, and if it is, which pieces. For now I'll just add application.properties:
spring.h2.console.enabled=true
spring.h2.console.path=/h2_console
spring.datasource.url=jdbc:h2:~/studentlist
spring.datasource.platform=h2
spring.datasource.initialization-mode=always
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.generate-ddl=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
logging.level.org.springframework=warn
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace
logging.level.org.hibernate.SQL=warn
logging.level.io.netty=warn
spring.datasource.maximum-pool-size=100
Adding either of these two dependencies, spring-boot-starter-data-r2dbc or r2dbc-h2, without the second one is enough to cause this error:
2020-10-20 15:31:26.008 WARN 11580 --- [ main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentService': Unsatisfied dependency expressed through field 'studentRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.freelance.studentlist.repository.StudentRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
2020-10-20 15:31:26.123 ERROR 11580 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field studentRepository in com.freelance.studentlist.service.StudentServiceImpl required a bean of type 'com.freelance.studentlist.repository.StudentRepository' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.freelance.studentlist.repository.StudentRepository' in your configuration.
Process finished with exit code 1
I removed JPA dependency and I'm currently trying to make things work with just r2dbc.
I suppose my application.properties would no longer be valid. Could you please help me with changing it? I use this code fragment from the guide:
public class R2DBCConfiguration extends AbstractR2dbcConfiguration {
#Bean
public H2ConnectionFactory connectionFactory() {
return new H2ConnectionFactory(
H2ConnectionConfiguration.builder()
.url("jdbc:h2:~/studentlist;DB_CLOSE_DELAY=-1;TRACE_LEVEL_FILE=4")
.username("sa")
.build());
}
}
I strongly suspect that such url is not valid for r2dbc. What would be valid substitution for jdbc:h2:~/studentlist URL in case of r2dbc H2 (not in-memory, just local DB)?
How should I change this block of code in application.properties ? URL in particular!
**spring.datasource.url=jdbc:h2:~/studentlist**
spring.datasource.platform=h2
spring.datasource.initialization-mode=always
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
Please help if you know! Can't google an appropriate example for now...
The spring.datasource is for the traditional Jdbc data source, to configure an R2dbc connection, use spring.r2dbc prefix instead in Spring Boot application.properties.
Check my Spring R2dbc example, if you are new to Spring Data R2dbc, the docs in Readme.md.

Is it possible for a module of a multi module project to use the repository folder of another?

I was following a tutorial to learn multi-modules in maven, but what was being presented raised a question:
Is there a possibility to create a multi-module project where only one module accesses the database and the others use this connection for their respective controllers?
Basically what I want is to use the same repository folder to scan with each datasourceconfig in all modules.
The structure I imagined and even started to implement was:
|--main
| |--moduleOne
| |--|--Java
| |-----|-DataSource
| |-----|-models
| |-----|-repositories
| |--|--Resources
| |-----|-application.properties
| |--moduleN
| |--|--Java
| |-----|-controller
| |-----|-service
| |--|--Resources
| |-----|-application.properties
The first module run perfectyly, the other need a conetion and I did It, but when I run, this module use a h2 database or not connect because moduleOne is using repository folder.
How can I fix for that services access those repositories?
POM ModuleOne
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>sig</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>moduleOne</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>moduleOne</name>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!-- SQL DEPENDENCIES -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>moduleOne</finalName>
</build>
</project>
POM ModuleN
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>sig</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>moduleN</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>moduleN</name>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!-- MODULE ON WHICH IT DEPENDS -->
<dependency>
<groupId>com.example.sig</groupId>
<artifactId>moduleOne</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>moduleN</finalName>
</build>
</project>
"The bean 'RepositoryX', defined in
br.example.sig.moduleone.repositories.RepositoryX defined in
EnableJpaRepositories declared on ServiceX, could not be registered. A
bean with that name has already been defined in
br.example.sig.moduleone.repositories.RepositoryX defined in
EnableJpaRepositories declared on DatasourceConfig and overriding is
disabled.
Consider renaming one of the beans or enabling overriding by setting
spring.main.allow-bean-definition-overriding=true"
I had a service with the annotations "#EntityScan" and "#EnableJpaRepositories" pointing to the same directory as my datasource in one of the modules, I put it there and forgot it.
I deleted the annotations, that was what generated the conflict and not the use for different modules.

Missing #ConditionalBean on StormpathWebMvcAutoConfiguration.stormpathApplicationResolver

While trying to add Stormpath to my existing Spring-Boot application, I have the following error on startup.
java.lang.IllegalStateException: Error processing condition on com.stormpath.spring.boot.autoconfigure.StormpathWebMvcAutoConfiguration.stormpathApplicationResolver
...
Caused by: java.lang.IllegalArgumentException: #ConditionalOnMissingBean annotations must specify at least one bean (type, name or annotation)
My pom :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<stormpath.version>1.1.1</stormpath.version>
</properties>
<dependencies>
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-default-spring-boot-starter</artifactId>
<version>${stormpath.version}</version>
</dependency>
</dependencies>
The stormpath version 1.1.1 works with spring-booth 1.4. I solved the problem by changing the spring-boot-starter-parent version to 1.4.1.

Resources