Integrate Spring Cloud Brixton.M1 into Spring Boot 1.2.6 application? - spring

It seems that i am missing something in my current setup of my pom.xml. Currently i have a Spring Boot application configured with a starter.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Now that i want to integrate this application with Spring Cloud Brixton.M1. According to the documentation i need to add the follow block:
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.M1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
And add for example Spring Cloud Turbine AMQP.
org.springframework.cloud
spring-cloud-starter-turbine-amqp
I also annotated the Spring Boot start class with:
#EnableTurbineAmqp
But now when i start the application i get the following error message:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.ResolvableType.forInstance(Ljava/lang/Object;)Lorg/springframework/core/ResolvableType;
It seems that there are 2 versions of Spring Core on the classpath which have a conflict. Is there a prefered way of excluding one or they other?

Spring Cloud Brixton M1 requires Spring Boot 1.3.x

Related

Spring Cloud DataFlow Server

I'm studying and doing some POC's with Spring Cloud DataFlow and I'm having some problems:
I am trying to start a Local Data Flow Server. In order to achieve this, I just created an Spring Boot Application and annotate this with #EnableDataFlowServer.
When I try to run, i get the following error:
11:54:53.307 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath:
[...]
11:54:53.395 [background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.13.Final
11:54:53.406 [background-preinit] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Found javax.persistence.Persistence on classpath containing 'getPersistenceUtil'. Assuming JPA 2 environment. Trying to instantiate JPA aware TraversableResolver
11:54:53.408 [background-preinit] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Instantiated JPA aware TraversableResolver of type org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.
11:54:53.413 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
11:54:53.414 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
11:54:53.414 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
11:54:53.415 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
11:54:53.590 [background-preinit] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
11:54:53.596 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
11:54:53.597 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.JPATraversableResolver as ValidatorFactory-scoped traversable resolver.
11:54:53.597 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
11:54:53.597 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
11:54:53.597 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
11:54:53.866 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava/lang/Object;)V
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:161)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:102)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:68)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:338)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:297)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
at com.arrobaautowired.springclouddataflowserver.SpringCloudDataflowServerApplication.main(SpringCloudDataflowServerApplication.java:12)
I was looking for help and I readed that it could be a pom's version problem. Actually my pom.xml is:
<-- [...] -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- DataFlow Server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-server-local-autoconfig</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
Can anyone help me?
Thanks for the update in the comments.
We used to promote the SCDF customization model in the past, but we have decided to move out of it for a variety of reasons, so that is why it is not mentioned in the docs. Hence, we removed it from Spring Initializr, too.
As for the error, it appears you're on Boot 2.x line, but SCDF is still on 1.5.x baseline. You could switch to Boot 1.5.17 and retry.
Also, as an FYI, SCDF's baseline is switching to Boot 2.1 in the coming weeks.

Maven spring-data-elasticsearch dependency Not Found

I have a spring boot app for which I want to use the dependency spring-data-elasticsearch. I'm using one of the latest version of Elasticsearch on my server (v5.4.x) so I had to use the latest snapshot of spring-data-elasticsearch (3.0.0.BUILD-SNAPSHOT).
According to the git page (link below) :
https://github.com/spring-projects/spring-data-elasticsearch/blob/master/README.md
I have to declare in my pom.xml a special repository where is located this specific version of the dependency, as you can see below :
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<name>Spring Snapshot Repository</name>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
<dependencies>
<!-- ELK -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.0.0.BUILD-SNAPSHOT</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
But I have the following error on my pom.xml :
Missing artifact org.springframework.data:spring-data-elasticsearch:jar:3.0.0.BUILD-SNAPSHOT
Anyone knows where the problem is coming from please ? I'm pulling hairs out of my head since 2 hours.
Thank you !
You probably have to add the Spring snapshot repository to your pom.xml
<repositories>
<repository>
<id>repository.spring.snapshot</id>
<name>Spring Snapshot Repository</name>
<url>http://repo.spring.io/snapshot</url>
</repository>
</repositories>
Thanks for your replies but I'm feeling like a fool. In my company we work with a nexus where all the repos are deployed, so I had to add the informations about the repos in my nexus too.
Sorry for the inconvenience.

Openshift - Spring Boot - Error creating new application - Failed to execute: 'control start'

I am trying to deploy a very simple Spring-Boot application on Openshift.
I am creating Tomcat 7 (JBoss EWS 2.0) Cartridge using openshift online from browser.
I am getting following errors while creating it.
and
Could not find any solution for that. Could someone help that what is going wrong here.
Git URL: https://github.com/bhaskey/testingcloud
Not sure what is the exact reason for error. However I find following issues in you code.
Java Version Not sure if JBoss EWS 2.0 supports 1.7(In generated pom.xml deafults to 1.7)
You are deploying on Tomcat server, however spring-boot-starter-web has transitive dependency on spring-boot-starter-tomcat. You need to set tomcat dependency to provided.
Your packing is jar and you've spring boot maven plugin not sure, how it is going to be deploy to tomcat server's webapps directory. it uses openshift profile to build the project. and your openshift profile might not work as expected.
In order for spring boot to run on external app server, you need to extend your main class with extends SpringBootServletInitializer
However I would suggest you to follow these steps to create spring boot project deployable to openshift.
Create Tomcat 7 (JBoss EWS 2.0) Cartridge from web console or Eclipse openshift plugin.
Clone the project to your local machine.
Modify pom.xml, add spring boot parent dependency and add only dependencies. Leave plugin as it is.
The updated pom.xml would look something like this.
<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.openshif</groupId>
<artifactId>cloudemo</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>cloudemo</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<repositories>
<repository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<java.version>1.6</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when
invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app
will need. -->
<!-- By default that is to put the resulting archive into the 'webapps'
folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<finalName>cloudemo</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Modify MainClass file
#SpringBootApplication
public class CloudemoApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(CloudemoApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(CloudemoApplication.class, args);
}
Since your application doesn't use spring boot plugin you might need to place all your html, css, js resources under webapps directory

Using #CrossOrigin in Spring Boot

I'm using latest Spring Boot (1.2.7.RELEASE). I would like to use the #CrossOrigin annotation from the package org.springframework.web.bind.annotation as described in CORS Support section in Spring docs.
I'd think I already have all the necessary dependencies (via Spring Boot defaults), but this is confusing: CrossOrigin is not found, even though stuff like RestController from the same package works!
Error:(8, 47) java: cannot find symbol
symbol: class CrossOrigin
location: package org.springframework.web.bind.annotation
What's going on? Has CrossOrigin been removed from later versions of Spring-MVC, or am I missing some dependency?
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Alright, looks like the latest Spring Boot release, 1.2.7.RELEASE at the moment, is too old to have a version of Spring MVC with CrossOrigin. (Spring Boot 1.2.7 uses Spring version 4.1.8).
I updated to latest Spring Boot 1.3 release candidate (1.3.0.RC1) and it works:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RC1</version>
</parent>
Also needed to specify spring-milestones repository in pom.xml to be able to use the non-release version.
<repositories>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
Update: override Spring version
As Stéphane Nicoll pointed out, a simpler way to get Spring 4.2.2 classes (such as CrossOrigin) into use is this:
<properties>
<!-- ... -->
<spring.version>4.2.2.RELEASE</spring.version>
</properties>
#CrossOrigin annotation is used to provide support for cross domains,
ie nothing but from different domains also we can access that service
by default it is true.
we can access the services from cross domains also.

WSO2 BAM 2.0 libraries in Maven

I'm trying to replicate the KPIAgent example in the WSO2 BAM ALPHA2 release but using maven to get the libraries required for the project to run.
So I've defined the following dependencies:
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.bam.agent</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.bam.data.publisher.util</artifactId>
<version>3.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.bam.service</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.google.common.wso2</groupId>
<artifactId>google-collect</artifactId>
<version>1.0.0.wso2v2</version>
</dependency>
<dependency>
<groupId>libthrift.wso2</groupId>
<artifactId>libthrift</artifactId>
<version>0.5.wso2v1</version>
</dependency>
<dependency>
<groupId>commons-pool.wso2</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.0.wso2v1</version>
</dependency>
Along with them I've defined the WSO2 repository this way:
<repository>
<id>wso2-maven2-repository</id>
<name>WSO2 Maven2 Repository</name>
<url>http://dist.wso2.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
</repository>
The problem I have is that the remote pom file for http://dist.wso2.org/maven2/org/wso2/carbon/org.wso2.carbon.bam.agent/3.2.4/org.wso2.carbon.bam.agent-3.2.4.pom refers to
<parent>
<groupId>org.wso2.carbon</groupId>
<artifactId>data-agents</artifactId>
<version>3.2.4</version>
</parent>
Which doesn't exist.
I assume this happens due to a rearrangement of the component's sources which is not fully reflected in the repository just yet; thus causing this inconsistency.
Question is then, which set of dependencies should I use to use EventReceiver in order to publish my own Events?
Thanks in advance for your support.
Seems it is not in the repo as you have mentioned for some reason. Can you try installing the pom given below to your local repository and see whether it works.
http://pastebin.com/AcmR1xmW

Resources