Spring Data makes spring unable to find JAXRS's #Provider? - jersey

I am using Spring + Jersey to build an API service .
Recently , I try to incorporate Spring Data to my server .
I haven't truly use any Repositories in my running code , just add one line in my app.xml :
<jpa:repositories base-package="destiny.web" entity-manager-factory-ref="entityManagerFactoryApp" />
But ! I notice my API not working , complaining "A message body writer for Java class xxx , and Java type class xxx , and MIME media type application/json was not found"
If I remove the "jpa:repositories ..." line in my xml , everything works fine !
and , all provider classes are registered by spring :
{http://*:8080-1} Registering Spring bean, apiResultJsonWriter, of type destiny.web.api.ApiResultJsonWriter as a provider class
{http://*:8080-1} Registering Spring bean, webApi, of type destiny.web.api.WebApi as a root resource class
{http://*:8080-1} Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
But , if I add "jpa:repositories..." line in my XML , only "root resources class" are registered :
{http://*:8080-1} CDI support is enabled
{http://*:8080-1} Using default applicationContext
{http://*:8080-1} Registering Spring bean, webApi, of type destiny.web.api.WebApi as a root resource class
{http://*:8080-1} Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
All JAXRS's #Provider(s) are missing !
I don't know if it is Spring-Data's bug ?
And how to solve it ?
environment :
spring-3.1
jersey-core-1.8.jar
jersey-server-1.8.jar
jersey-spring-1.8.jar
spring-data-jpa-1.0.3.RELEASE.jar
spring-data-commons-core-1.1.0.RELEASE.jar
server : resin-4.0.25
Related dependencies :
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.0.3.RELEASE</version>
</dependency>
( I tried to add jersey-json , but still not working )

You need to register the packages that contain classes annotated with #Provider
in Jersey 2 this is done via by calling the packages method in your ResourceConfig class.
I believe there is also a basepackages attribue you can put on the servlet. See here Autodiscover JAX-RS resources with CXF in a Spring application

Related

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.

Spring boot failing to start with Spring Cloud AWS Core dependency

I am writing a spring boot app that accesses stuff from an s3 bucket, but I get a NoClassDefFoundError when I use the starter spring-cloud-starter-aws dependency from the spring initializer.
Am I missing some other dependency here?
Below are my dependencies.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I also defined the dependencyManagement block for spring-cloud-dependencies and use Edgware.SR1 as my spring-cloud-version.
My app fails with the following error when starting up.
2018-01-24 12:20:25.642 INFO 1980 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-24 12:20:25.666 ERROR 1980 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.art.productattribution.consumerintegration.ConsumerIntegrationApplication]; nested exception is java.lang.NoClassDefFoundError: com/amazonaws/AmazonClientException
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:616) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
Not sure what am I missing here? Please let me know if you need any more details with this. The version of spring boot I am using is 1.5.9.RELEASE
The correct dependency is the spring-cloud-aws-context. Add the following in your pom file (version 1.2.2 as of Nov 22, 2017):
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-aws-context -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
Below are the Spring Cloud AWS modules:
Spring Cloud AWS Core is the core module of Spring Cloud AWS providing basic services for security and configuration setup. Developers will not use this module directly but rather through other modules. The core module provides support for cloud based environment configurations providing direct access to the instance based EC2 metadata and the overall application stack specific CloudFormation metadata.
Spring Cloud AWS Context delivers access to the Simple Storage Service via the Spring resource loader abstraction. Moreover developers can send e-mails using the Simple E-Mail Service and the Spring mail abstraction. Further the developers can introduce declarative caching using the Spring caching support and the ElastiCache caching service.
Spring Cloud AWS JDBC provides automatic datasource lookup and configuration for the Relational Database Service which can be used with JDBC or any other support data access technology by Spring.
Spring Cloud AWS Messaging enables developers to receive and send messages with the Simple Queueing Service for point-to-point communication. Publish-subscribe messaging is supported with the integration of the Simple Notification Service.
Ref: http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_using_amazon_web_services
It seems com.amazonaws.AmazonClientException is not found in the classpath. I think you can add the following dependency in your POM.xml file to solve this issue.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-core</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
You need to include dependency mentioned by #alltej. Also you need to add below property in application.properties file if you are running on local.
cloud.aws.stack.auto=false

Spring boot and apache spark - container conflict

I am trying to use spring boot 1.1.5 and apache spark 1.0.2 together in project. Look like apache spark uses Jetty container internally and I have configured spring-boot to use Tomcat container. However application startup fails with some securityException at root cause. If I see full stack trace looks like spring boot trying to initialize "jettyEmbeddedServletContainerFactory" which it shouldn't in first place. It probably picks it up from classpath due to jetty presence via spark. If I exclude jetty from spark and run again I don't see same error again but then SparkContext initialization fails due to not finding jetty. How do i tell spring-boot runtime to look for "TomcatEmbeddedServletContainerFactory" instead of jetty one?
I got "java.lang.SecurityException: class "javax.servlet.http.HttpSessionIdListener"'s signer information does not match signer information of other classes in the same package"
To fix this issue I was need to remove all javax.servlet dependencies.
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.3.1</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
</exclusion>
</exclusions>
</dependency>
#Joakim Erdfelt, Thanks.
I was just waiting to see if someone is familiar with this situation and if it's just a small configuration change. As it turns out it is! #Configuration
#EnableAutoConfiguration(exclude={EmbeddedServletContainerFactory.class})
public class MyConfiguration { }
I defined my own "EmbeddedServletContainerFactory" bean as a "org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContaine‌​rFactory" and it started working as I expected.

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