How to deploy Maven project to Glassfish Server in Intellij Idea 13 - maven

I am developing a sample Java EE applicaiton with Intellij Idea 13. Simply, my project is a Maven project and has JPA end EJB modules. But when deploying and running application on Glassfish server I get errors.
I created a Maven project named SimpleEE and added JPA, EJB modules.
Here is my project structure:
|-SampleEE
| |+.idea
| |-src
| | |-main
| | | |-java
| | | | |-beans
| | | | | |-MyBean.java
| | | | |-entities
| | | | |-Staff.java
| | | |-resources
| | | |-META-INF
| | | |-ejb-jar.xml
| | | |-persistence.xml
| | |+test
| |-pom.xml
| |-SampleEE.iml
| |-SampleEE.jpr
|+ExternalLibraries
MyBean.java:
package beans;
import entities.Staff;
import javax.annotation.PostConstruct;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
#Startup
#LocalBean
#Singleton
public class MyBean {
public MyBean() {
}
#PostConstruct
public void myMain() {
EntityManager em = Persistence.createEntityManagerFactory("mysqlPU").createEntityManager();
em.getTransaction().begin();
Staff staff = new Staff();
staff.setAge(44);
staff.setGender("M");
staff.setSalary(123);
staff.setName("Staff Name");
em.persist(staff);
em.getTransaction().commit();
}
}
Staff.java
package entities;
import javax.persistence.*;
#Entity
public class Staff {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "STAFF_ID")
private int id;
#Column(name = "NAME")
private String name;
#Column(name = "AGE")
private Integer age;
#Column(name = "GENDER")
private String gender;
#Column(name = "SALARY")
private Integer salary;
#Lob
#Column(name = "IMAGE", nullable = true)
private byte[] image;
// Getters and setters
// ...
#Override
public int hashCode() {
// implementation ignored here for simplicity
}
#Override
public boolean equals(Object o) {
// implementation ignored here for simplicity
}
}
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="mysqlPU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>entities.Staff</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dbName"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="mysqlUsername"/>
<property name="javax.persistence.jdbc.password" value="mysqlPassword"/>
</properties>
</persistence-unit>
</persistence>
pom.xml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SampleEE</groupId>
<artifactId>SampleEE</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
</dependencies>
</project>
I created an EJB Application:Exploded artifact from project structure. In Run/Debug configurations window I built a Glassfish configuration. But when running this configuration, Idea complains that it can not find classes in mysql jdbc driver and shows errors emerging from this error. Server is started but application is not deployed. Error message snippet from Idea output log:
....
[2013-12-13 04:07:31,362] Artifact SampleEE:ejb exploded: Artifact is being deployed, please wait...
[2013-12-13 04:07:33,011] Artifact SampleEE:ejb exploded: Error during artifact deployment. See server log for details.
[2013-12-13 04:07:33,018] Artifact SampleEE:ejb exploded: java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton MyBean. Please see server.log for more details.
Last error in Glassfish log
....
Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [com.mysql.jdbc.Driver] not found.
....
I guess jar files of libraries are not deployed. But my maven configuration is valid. M2_HOME is set correctly and IDEA resolves maven path. The jar files are also available in local repository.
I created a same structured project in Netbeans and it runs succesfully. I don't know what I am doing wrong or what configuration parameters I am missing.

You need to add a JavaEE module and add create a JavaEE artifact. Then add all libraries you need to that artifact.

Related

How to convert XML to String with JAXB and spring-boot?

When I run a mvn spring-boot:run on the folder that has the pom.xml file the application starts and serializes a POJO into a XML correctly, but when I do it by going to the target folder and starting it by using java -jar in the jar file I get javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath caused by .java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory.
In my maven I have the following JAXB dependencies:
<!-- JAXB API -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<!-- JAXB Runtime -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.5</version>
<scope>runtime</scope>
</dependency>
Here's the code that serializes a POJO into XML:
private static final Pattern REMOVE_HEADER = Pattern.compile("\\<\\?xml(.+?)\\?\\>");
public static <T> String toXML(final T data) {
try {
final var jaxbMarshaller = JAXBContext.newInstance(data.getClass()).createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
final var sw = new StringWriter();
jaxbMarshaller.marshal(data, sw);
return XMLUtils.REMOVE_HEADER.matcher(sw.toString()).replaceAll("").strip();
} catch (final JAXBException e) {
XMLUtils.LOGGER.error("Error while converting POJO to XML. ERROR: {}.", e.getMessage(), e);
}
return "";
}
Here's the log when I start the application with java -jar:
2021-12-26 21:19:14,526 [ForkJoinPool.commonPool-worker-11] ERROR com.enterprise.system.shared.util.XMLUtils - Error while converting POJO to XML. ERROR: Implementation of JAXB-API has not been found on module path or classpath..
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:232)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:375)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
at com.enterprise.system.shared.util.XMLUtils.toXML(XMLUtils.java:26)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:952)
at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:926)
at java.base/java.util.stream.AbstractTask.compute(AbstractTask.java:327)
at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:230)
... 17 more
Here's an image of the generated spring-boot fat jar with the JAXB dependencies:
Here's my dependency tree:
--- maven-dependency-plugin:3.2.0:tree (default-cli) # java-eleven-jaxb-hell ---
com.enterprise.system:java-eleven-jaxb-hell:jar:0.0.1-SNAPSHOT
+- org.slf4j:slf4j-log4j12:jar:1.7.32:compile (optional)
| +- org.slf4j:slf4j-api:jar:1.7.32:compile (optional)
| \- log4j:log4j:jar:1.2.17:compile (optional)
+- org.springframework.boot:spring-boot-autoconfigure:jar:2.6.2:compile
| \- org.springframework.boot:spring-boot:jar:2.6.2:compile
| +- org.springframework:spring-core:jar:5.3.14:compile
| | \- org.springframework:spring-jcl:jar:5.3.14:compile
| \- org.springframework:spring-context:jar:5.3.14:compile
| +- org.springframework:spring-aop:jar:5.3.14:compile
| +- org.springframework:spring-beans:jar:5.3.14:compile
| \- org.springframework:spring-expression:jar:5.3.14:compile
+- org.projectlombok:lombok:jar:1.18.22:provided
+- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile
| \- jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
\- com.sun.xml.bind:jaxb-impl:jar:2.3.5:runtime
\- com.sun.activation:jakarta.activation:jar:1.2.2:runtime
And finally, here are my model classes:
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
#XmlRootElement(name = "finans")
#XmlAccessorType(XmlAccessType.FIELD)
#Data
#NoArgsConstructor
#AllArgsConstructor
public class FinanTokenDTO {
#XmlAttribute
private String pln;
#XmlAttribute
private String ope;
#XmlAttribute
private String mod;
#XmlAttribute
private String mis;
#XmlAttribute
private String val;
#XmlAttribute
private String car;
#XmlAttribute
private String dti;
#XmlAttribute
private String dtf;
#XmlAttribute
private String ota;
#XmlElement
private FinanDTO finan;
}
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
#XmlRootElement(name = "finan")
#XmlAccessorType(XmlAccessType.FIELD)
#Data
#NoArgsConstructor
#AllArgsConstructor
public class FinanDTO {
#XmlAttribute
private String prd;
#XmlAttribute
private String pkg;
#XmlAttribute
private String val;
#XmlAttribute
private String fty;
}
I am using java 11 and I am aware that in java 11 JAXB was removed from the SE JDK because it is considered as a EE feature.
I am not able to execute it using mvn spring-boot:run in production environment because of the size of the docker image and security related issues using docker container.
Since Spring Boot generates a fat jar, shouldn't the application run with java -jar applied to the spring boot fat jar generated file the same way as it does with mvn spring-boot:run inside the folder with pom.xml?
EDIT:
After a lot of digging and testing I found that the problem occurs when we try to marshall several valid POJOs using parallel stream instead of stream on the POJOs list. I uploaded the code in java-eleven-jaxb-hell to better understanding, unfortunatelly I cannot change parallelStream to stream because of performance issues. Just to remember, for the problem to happen you have to run java -jar against spring-boot generated fat jar in target folder.
Try adding the next dependency:
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.1</version>
</dependency>
I suggest you to replace the JAXB-impl from Sun by the one from Glassfish:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.5</version>
</dependency>
Generally speaking, Sun does not exists anymore since years, and the package might be there only for compatibility. The recommended JAXB implementation today comes from Glassfish.

Depending on maven dependency scope compiled or provided produces Ambiguous Bean or ClassNotfoundException

Environment:
Java 11
JBoss 7.2
Maven 3.5
I have a project with many maven modules and a common for all. Depend on the scope of dependency compile or provided I am getting WELD-001414: Bean name is ambiguous or java.lang.ClassNotFoundException.
How to solve these two errors to once?
When pom.xml (app-back) has dependency app-commons
When app-commons is scope provided
ERROR java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JRException
When app-commons is scope compiled
ERROR WELD-001414: Bean name is ambiguous. Name version resolves to beans: [Managed Bean [class es.caib.app.commons.utils.Version] with qualifiers [#Default #Any #Named], Managed Bean [class es.caib.app.commons.utils.Version] with qualifiers [#Default #Any #Named]]"}}
Modules:
app (pom)
app-ear
app-back (dependency to app-commons)
app-front (dependency to app-commons)
app-commons (jasperreport dependency)
...
app-commons have ReportManager.java that needs jasper dependency and Version.java of type #ApplicationScope
pom.xml app-commons
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>es.caib.accfor</groupId>
<artifactId>app</artifactId>
<version>8.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>app-commons</artifactId>
<packaging>jar</packaging>
<name>app-commons</name>
...
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.15.0</version>
</dependency>
</dependencies>
...
Version.java (app-commons)
...
#Named
#ApplicationScoped
public class Version {
private String version;
private String buildTime;
private String scmRevision;
private String jdkVersion;
private String projectName;
...
ReportManager.java (app-commons)
public class ReportManager {
...
public static void addParam(Map<String, Object> params, String nom, byte[] compiledReport) throws ReportException {
try {
params.put(nom, SerializationUtils.deserialize(compiledReport));
} catch (Exception e) {
throw new ReportException("Error deserialize compiledReport.");
}
}
...
In app-back module I call ReportManager.addParam()
SessionScoped.java (app-back)
#Named
#SessionScoped
public class SessionBean implements Serializable {
#Inject
private Version version;
...
StartupListener.java (app-back)
#WebListener
public class StartupListener implements ServletContextListener {
private static final Logger LOG = LoggerFactory.getLogger(StartupListener.class);
#Inject
private Version version;
...
Because of transitive dependencies are not included when dependency is provided, so I had to restructure the modules this way.
Modules:
app (pom)
app-ear
jasperreports (compiled) MOVED FROM APP-COMMONS
app-back
app-commons (provided)
app-front
app-commons (provided)
app-commons
...
I was not able to change app-commons dependency to compiled because it is dependent of app-front and app-back. In app-commons as compiled I have an #ApplicationScope class that it would produce ambiguous Beans pointing to the class in app-commons because of jakartaee context management.

Adding a dependency to a working Spring Boot project invalidates all JUnit

I have 2 Eclipse projects and each one is has services managed by Spring. I use Spring Boot starter dependencies for each of them. Each one works properly, and can be tested with JUnit launched via SpringRunner.class and #SpringBootTest.
Now, I want to call some services from project 1 in project 2, so I add a dependency in project 2 pom.xml and I add
#ComponentScan(basePackages="com.project1")
From then on, I can't launch any JUnit, it complains about dataSource not being set, like if configs where mixing randomly.
My question is : what are the recommended practices when you create a Spring Boot App and you want to isolate some features in a separate project (here XML features) ? If u can't have 2 spring boot app with one dependant of the other, what are the spring dependencies you need so the spring boot project can deal with the non spring boot dependency, and so that u can still launch JUnit using Spring runner locally ?
Do I need to pick Spring dependencies one by one (core, bean, context, test, log4j, slf4j, junit, hamcrest, ...) like before Spring boot exist to do this ?
See my comment on why the possible duplicate is different.
After removing all Spring boot dependencies from my module project, I still have the error as soon as I add the "ComponentScan" to scan the module services.
Here is my DB config (main project depending on a xml module) to be clear on the package config. This config WORKS perfectly until I add the ComponentScan on a package from the module project :
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories(basePackages="fr.my.project.repository")
class PersistenceContext {
private static final String[] ENTITY_PACKAGES = { "fr.my.project.model" };
private static final String PROP_DB_DRIVER_CLASS = "db.driver";
private static final String PROP_DB_PASSWORD = "db.password";
private static final String PROP_DB_URL = "db.url";
private static final String PROP_DB_USER = "db.username";
private static final String PROP_HIBERNATE_DIALECT = "hibernate.dialect";
private static final String PROP_HIBERNATE_FORMAT_SQL = "hibernate.format_sql";
private static final String PROP_HIBERNATE_HBM2DDL_AUTO = "hibernate.hbm2ddl.auto";
private static final String PROP_HIBERNATE_SHOW_SQL = "hibernate.show_sql";
/**
* Creates and configures the HikariCP datasource bean.
*
* #param env
* The runtime environment of our application.
* #return
*/
#Bean(destroyMethod = "close")
DataSource dataSource(Environment env) {
HikariConfig dataSourceConfig = new HikariConfig();
dataSourceConfig.setDriverClassName(env.getRequiredProperty(PROP_DB_DRIVER_CLASS));
dataSourceConfig.setJdbcUrl(env.getRequiredProperty(PROP_DB_URL));
dataSourceConfig.setUsername(env.getRequiredProperty(PROP_DB_USER));
dataSourceConfig.setPassword(env.getRequiredProperty(PROP_DB_PASSWORD));
return new HikariDataSource(dataSourceConfig);
}
/**
* Creates the bean that creates the JPA entity manager factory.
*
* #param dataSource
* The datasource that provides the database connections.
* #param env
* The runtime environment of our application.
* #return
*/
#Bean
LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, Environment env) {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource);
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
entityManagerFactoryBean.setPackagesToScan(ENTITY_PACKAGES);
Properties jpaProperties = new Properties();
// Configures the used database dialect. This allows Hibernate to create SQL
// that is optimized for the used database.
jpaProperties.put(PROP_HIBERNATE_DIALECT, env.getRequiredProperty(PROP_HIBERNATE_DIALECT));
// Specifies the action that is invoked to the database when the Hibernate
// SessionFactory is created or closed.
jpaProperties.put(PROP_HIBERNATE_HBM2DDL_AUTO, env.getRequiredProperty(PROP_HIBERNATE_HBM2DDL_AUTO));
// If the value of this property is true, Hibernate writes all SQL
// statements to the console.
jpaProperties.put(PROP_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROP_HIBERNATE_SHOW_SQL));
// If the value of this property is true, Hibernate will use prettyprint
// when it writes SQL to the console.
jpaProperties.put(PROP_HIBERNATE_FORMAT_SQL, env.getRequiredProperty(PROP_HIBERNATE_FORMAT_SQL));
entityManagerFactoryBean.setJpaProperties(jpaProperties);
return entityManagerFactoryBean;
}
/**
* Creates the transaction manager bean that integrates the used JPA provider with the Spring transaction mechanism.
*
* #param entityManagerFactory
* The used JPA entity manager factory.
* #return
*/
#Bean
JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory);
return transactionManager;
}
}
and after adding :
#ComponentScan(basePackages="fr.my.module.xml.service")
I get this error when launching any Junit :
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
Here is a temporary answer on how to configure the dependency project, but I hope some easier way benefiting of Spring Boot shortcuts for all app modules exist.
pom.xml with manual minimal dependencies :
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.14.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.11</version>
</dependency>
Manual test config :
#RunWith(SpringRunner.class)
#ContextConfiguration(loader=AnnotationConfigContextLoader.class, classes=AppConfig.class)
public class XmlTest {
Manual app config :
#Configuration
#ComponentScan(basePackages="my.package.xml")
public class AppConfig {
}
Sooooooo after doing all these tries, Spring Boot may not be the cause of this problem at all.
The thing is I was adding #ComponentScan(basePackages="fr.package.xml") hoping to complete the default package scanning, but it was overriding it.
The proper way to add a package, is to redeclare explicitely the default package before adding the new package :
#ComponentScan(basePackages={"fr.package.xml", "fr.package.persistence"})
My other answer was about setting up manual minimal dependencies for a module in a Spring Boot app. But here is an example of using Spring boot special dependencies in the module which is not the main app :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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>
</dependencies>
Then, you don't declare "#SpringBootApplication" in a main class in src/main/java where it may break the global packaging, but you set it up inside your test class :
#RunWith(SpringRunner.class)
#SpringBootTest("service.message=Hello")
public class MyServiceTest {
#Autowired
private MyService myService;
#Test
public void contextLoads() {
assertThat(myService.message()).isNotNull();
}
#SpringBootApplication
static class TestConfiguration {
}
}
source : https://github.com/spring-guides/gs-multi-module/tree/master/complete

JBoss Fuse/REST DSL - Why do my modifications (to use IBM MQ) not work?

BACKGROUND:
I assembled a "relatively" compact JBossFuse, REST-DSL example (from disparate posts/articles) that routes to an ActiveMQ queue (see working example, further below).
PROBLEM: I want to route to an "IBM MQ" queue, instead.
QUESTION:
What has to change for me to route to "IBM MQ" instead of "ActiveMQ"?
I've tried the following...:
(A) building an IBM MQ "support bundle" and deploying it to Fuse and adding the dep. to the app's pom.xml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ibm</groupId>
<artifactId>ibm-mq-lib</artifactId>
<version>9.0.0.0</version>
<description>ibm-mq-lib</description>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>com.ibm.mq.osgi</groupId>
<artifactId>allclient</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/OSGi/com.ibm.mq.osgi.allclient_9.0.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq.osgi</groupId>
<artifactId>allclientprereqs</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/OSGi/com.ibm.mq.osgi.allclientprereqs_9.0.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>allclient</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/com.ibm.mq.allclient.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>traceControl</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/com.ibm.mq.traceControl.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>fscontext</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/fscontext.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>jms</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/jms.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>providerutil</artifactId>
<version>9.0.0.0</version>
<systemPath>C:/tools/wmq/JavaSE/providerutil.jar</systemPath>
<scope>system</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Description>description</Bundle-Description>
<Bundle-Vendor>IBM MQ 9.0.0.0</Bundle-Vendor>
<Import-Package></Import-Package>
<Export-Package>*</Export-Package>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<name>ibm-mq-lib</name>
</project>
(B) modified the "camel-route.xml" file (added the following)
...
<bean id="connectionFactory"
class="com.ibm.mq.jms.MQConnectionFactory">
<property name="transportType" value="1"/>
<property name="hostName" value="localhost"/>
<property name="port" value="1414"/>
<property name="queueManager" value="QM1"/>
<property name="channel" value="DEV.APP.SVRCONN" />
</bean>
<bean id="ibmMqConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="ibmMq"
class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="ibmMqConfig"/>
</bean>
</blueprint>
(C) modified "CamelRestRoutes.java" file to point to the IBM MQ queue (instead of the ActiveMQ queue)...
...
from("direct:thingZ")
.log("---------------------- (CCC) ----------------------> direct:thingZ...:" + body().toString())
.to("ibmMq:queue:bubblegum?jmsMessageType=Text&exchangePattern=InOnly");
Call the "getAll" method in the REST service results in an exception with the following log/exception output
...
WorkQueueMananger Contents
--------------------------
| Maintain ThreadPool size :- false
| Maximum ThreadPool size :- -1
| ThreadPool inactive timeout :- 0
| unavailable - :- com.ibm.msg.client.commonservices.CSIException: JMSCS0002
Runtime properties
------------------
| Available processors :- 4
| Free memory in bytes (now) :- 737153288
| Max memory in bytes :- 954728448
| Total memory in bytes (now) :- 875036672
Component Manager Contents
--------------------------
Common Services Components:
Messaging Provider Components:
| CMVC :- p900-L160512.4
| Class Name :- class com.ibm.msg.client.wmq.factories.WMQComponent
| Component Name :- com.ibm.msg.client.wmq
| Component Title :- IBM MQ JMS Provider
| Factory Class :- class com.ibm.msg.client.wmq.factories.WMQFactoryFactory
| Jar location :- bundle://530.0:1/com/ibm/msg/client/wmq/factories/WMQComponent.class
| Version :- 9.0.0.0
Provider Specific Information
-----------------------------
Overview of JMS System
Num. Contexts : 0
Num. Connections : 0
Num. Sessions : 0
Num. Consumers : 0
Num. Producers : 0
Detailed JMS System Information
Contexts :
Connections :
Sessions :
Consumers :
Producers :
2017-08-08 09:44:57,407 | ERROR | estlet-672518929 | DefaultErrorHandler | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Failed delivery for (MessageId: ID-AAXA22A747-53217-1502199741603-0-3 on ExchangeId: ID-AAXA22A747-53217-1502199741603-0-2). Exhausted after delivery attempt: 1 caught: org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: null; nested exception is com.ibm.mq.MQException: JMSCMQ0001: JMSCMQ0001, 2, MQCC_FAILED, 2195, MQRC_UNEXPECTED_ERROR
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[route1 ] [route1 ] [http://localhost:8182/service/getAll?restletMethods=GET ] [ 4126]
[route1 ] [restBinding1 ] [ ] [ 4]
[route1 ] [route1 ] [direct:thingX ] [ 4119]
[route2 ] [to1 ] [bean:camelRestService?method=getAll ] [ 7]
[route2 ] [log1 ] [log ] [ 1]
[route2 ] [to2 ] [direct:thingY ] [ 4110]
[route3 ] [log2 ] [log ] [ 1]
[route3 ] [to3 ] [direct:thingZ ] [ 4109]
[route4 ] [log3 ] [log ] [ 0]
[route4 ] [to4 ] [ibmMq:queue:mylocalqueue?jmsMessageType=Text&exchangePattern=InOnly ] [ 4109]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: null; nested exception is com.ibm.mq.MQException: JMSCMQ0001: JMSCMQ0001, 2, MQCC_FAILED, 2195, MQRC_UNEXPECTED_ERROR
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:452)[244:org.apache.camel.camel-jms:2.17.0.redhat-630187]
at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:414)[244:org.apache.camel.camel-jms:2.17.0.redhat-630187]
at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:368)[244:org.apache.camel.camel-jms:2.17.0.redhat-630187]
at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:154)[244:org.apache.camel.camel-jms:2.17.0.redhat-630187]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:91)[232:org.apache.camel.camel-core:2.17.0.redhat-630187]
at org.apache.camel.component.restlet.RestletConsumer$1.handle(RestletConsumer.java:68)[304:org.apache.camel.camel-restlet:2.17.0.redhat-630187]
at org.apache.camel.component.restlet.MethodBasedRouter.handle(MethodBasedRouter.java:54)[304:org.apache.camel.camel-restlet:2.17.0.redhat-630187]
at org.restlet.routing.Filter.doHandle(Filter.java:150)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.handle(Filter.java:197)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Router.doHandle(Router.java:422)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Router.handle(Router.java:639)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.doHandle(Filter.java:150)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.handle(Filter.java:197)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Router.doHandle(Router.java:422)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Router.handle(Router.java:639)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.doHandle(Filter.java:150)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:140)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.handle(Filter.java:197)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.doHandle(Filter.java:150)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.routing.Filter.handle(Filter.java:197)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.Component.handle(Component.java:408)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.Server.handle(Server.java:507)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.connector.ServerHelper.handle(ServerHelper.java:63)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:143)[303:org.restlet:2.3.6.v20160126-1627]
at org.restlet.engine.connector.HttpServerHelper$1.handle(HttpServerHelper.java:64)[303:org.restlet:2.3.6.v20160126-1627]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)[:1.8.0_131]
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)[:1.8.0_131]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)[:1.8.0_131]
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)[:1.8.0_131]
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)[:1.8.0_131]
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)[:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_131]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]
Caused by: com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: null
at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:595)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:215)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:422)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:8475)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:7814)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl._createConnection(JmsConnectionFactoryImpl.java:299)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:236)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6024)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jms.MQConnectionFactory.createConnection(MQConnectionFactory.java:6049)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:456)[243:org.apache.servicemix.bundles.spring-jms:3.2.16.RELEASE_2]
... 67 more
Caused by: com.ibm.mq.MQException: JMSCMQ0001: JMSCMQ0001, 2, MQCC_FAILED, 2195, MQRC_UNEXPECTED_ERROR
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
... 76 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2195;AMQ9204: Connection to host 'localhost(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2195],3=localhost(1414),5=JmqiDefaultThreadPool.enqueue]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:2280)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1285)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:355)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
... 75 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2195
at com.ibm.mq.jmqi.JmqiDefaultThreadPool.enqueue(JmqiDefaultThreadPool.java:97)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.setUpAsyncMode(RemoteConnection.java:1979)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.initSess(RemoteConnection.java:1741)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:863)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:409)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:305)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:146)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1721)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
... 77 more
Caused by: com.ibm.msg.client.commonservices.CSIException: JMSCS0002
at com.ibm.msg.client.commonservices.workqueue.PIWorkQueueManager.enqueueItem(PIWorkQueueManager.java:55)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.commonservices.workqueue.WorkQueueManager.enqueue(WorkQueueManager.java:232)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.msg.client.commonservices.workqueue.WorkQueueManager.enqueue(WorkQueueManager.java:200)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
at com.ibm.mq.jmqi.JmqiDefaultThreadPool.enqueue(JmqiDefaultThreadPool.java:79)[530:com.ibm.mq.osgi.allclient:9.0.0.0]
... 84 more
2017-08-08 09:44:57,429 | INFO | estlet-672518929 | LogService | 303 - org.restlet - 2.3.6.v20160126-1627 | 2017-08-08 09:44:57 0:0:0:0:0:0:0:1 - - 8182 GET /service/getAll/ - 500 8856 0 4140 http://localhost:8182 Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0 -
For comparison/context, BELOW, is the working project that routes to an ActiveMQ queue...
Here is the project structure
aaa.bbb.ccc.CamelRestService.java
package aaa.bbb.ccc;
import aaa.bbb.ccc.model.CamelRestPojo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
#Path("/service/")
public class CamelRestService {
Map<Long, CamelRestPojo> itemMap = new HashMap<>();
public CamelRestService() {
init();
}
#GET
#Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
#Path("/getAll/")
public Collection<CamelRestPojo> getAll() {
return itemMap.values();
}
final void init() {
CamelRestPojo o = new CamelRestPojo();
o.setName("JOE BLOW");
o.setId(100);
itemMap.put(o.getId(), o);
}
}
aaa.bbb.ccc.CamelRestRoute.java
package aaa.bbb.ccc;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
public class CamelRestRoutes extends RouteBuilder {
public CamelRestRoutes() {
}
#Override
public void configure() throws Exception {
restConfiguration().component("restlet")
.host("localhost")
.port(8182)
.bindingMode(RestBindingMode.json_xml);
rest("/service")
.bindingMode(RestBindingMode.json_xml)
.get("/getAll")
.produces("application/json")
.to("direct:thingX");
from("direct:thingX")
.to("bean:camelRestService?method=getAll")
.log("---------------------- (AAA) ----------------------> direct:thingX...:" + body().toString())
.to("direct:thingY");
from("direct:thingY")
.log("---------------------- (BBB) ----------------------> direct:thingY...:" + body().toString())
.to("direct:thingZ");
from("direct:thingZ")
.log("---------------------- (CCC) ----------------------> direct:thingZ...:" + body().toString())
.to("activemq:queue:bubblegum?jmsMessageType=Text&exchangePattern=InOnly");
}
}
aaa.bbb.ccc.model.CamelRestPojo.java
package aaa.bbb.ccc.model;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "camelRestPojo")
public class CamelRestPojo implements Serializable {
#XmlElement
private long id;
#XmlElement
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Override
public String toString() {
return "CamelRestPojo{" + "id=" + id + ", name=" + name + '}';
}
}
camel-route.xml
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
">
<camel:camelContext id="aaa.bbb.ccc.routing.poc" xmlns="http://camel.apache.org/schema/blueprint">
<packageScan>
<package>aaa.bbb.ccc</package>
</packageScan>
</camel:camelContext>
<bean id="camelRestService" class="aaa.bbb.ccc.CamelRestService"/>
<bean id = "activemq" class = "org.apache.activemq.camel.component.ActiveMQComponent">
<property name = "brokerURL" value = "tcp://localhost:61616"/>
<property name = "userName" value = "admin"/>
<property name = "password" value = "admin"/>
</bean>
</blueprint>
pom.xml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa.bbb.ccc</groupId>
<artifactId>camelRest</artifactId>
<version>1</version>
<packaging>bundle</packaging>
<name>camelRest</name>
<description>camelRest</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.11.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Export-Package>aaa.bbb.ccc*</Export-Package>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
test url/return value
URL:
http://localhost:8182/service/getAll/
RETURNS:
[{"id": 100,"name": "JOE BLOW"}]
Environment
IBM MQ server 9.0.3.0
IBM MQ client 8.0.0.7
jdk1.8.0_131
jboss-fuse-6.3.0.redhat-187
I've worked on a few Fuse/W-MQ integration exercises. Bundling the W-MQ client drivers into your application probably won't work on Fuse. You need to install the W-MQ client JARs into the Fuse run-time. IBM provides OSGi-compliant versions for that purpose.
My recollection is that there are nine in total, but not all are needed in all configurations. You can install them using osgi:install at the Karaf prompt, or just dump them in the deploy/ directory for testing purposes. Some configuration changes might need to be made in Fuse -- these depend on the specific version combination.
Your connection factory configuration looks broadly correct.
The "allcient" jars contain all of the other client bundles that Kevin was mentioning.
I'm a bit puzzled by what I am seeing, however. I downloaded the IBM MQ 9.0.3 client jars, and there is only the "com.ibm.mq.allclient.jar" in the zip.
For MQ 8, you would have the "com.ibm.mq.osgi.allclient.jar" and "com.ibm.mq.osgi.allclientprereqs.jar" bundles. The problem there is that the prereq bundle included the javax.jms interfaces. You would have to modify the prereq bundle to remove the JMS api jar in order to use it on Fuse. I do not know if this is still the case for MQ 9.
Specifically for Fuse 6.3:
My recollection is that Fuse 6.3 is tested against the client runtime for W-MQ 8, without needing modifications in Fuse. I can't remember whether that was with the individual 8-9 IBM bundles, or with the "allclient" bundle that Doug mentions. In any event, you need to avoid getting into a situation where you have a JMS 2.0 API JAR (that is, the bundle that includes the javax.jms.xxx classes) from both W-MQ and from Fuse -- they will clash. So if you install xxx_allclient.jar, you either need to not install xxx_allclientprereqs.jar, or uninstall the Fuse jms-api bundle from the Fuse runtime. If you go the route of using the heap of 8 or 9 bundles, you should install them all except one called something like xxx_jms.prereq_xxx.jar.
You can install using osgi:install or, for development, just copy them into the deploy/ directory on Fuse. In Fabric8 you'll need eventually to put the IBM JARs into some sort of repository and then create a profile that references them; but testing without Fabric8 in the first instance is probably worthwhile, to remove that additional source of complexity.
I haven't unpacked the W-MQ 9 allclient.jar, so I don't know what's inside it. If it contains javax.jms.xxx classes, either directly or in another internal JAR, then I guess you'll either need to unpack and repack the JAR without these classes, or uninstall the Fuse jms-api bundle.
In any event, Fuse 6.3 with W-MQ 8 client runtime is a good combination, and probably the easiest Fuse/W-MQ combination to get working. You don't necessarily have to use the W-MQ client runtime whose version that matches the W-MQ broker version, if a different client is easier to install on Fuse. However, you should check IBM's compatibility statement before going this way. My recollection is that the W-MQ 8 client runtime is certified by IBM to work with any 7.5.x broker, but I'm not sure whether compatibility works in the opposite direction.
FWIW my recommendation is that you shouldn't be afraid to use a bit of trial-and-error. I've been working with Fuse and W-MQ for a couple of years, and I still find I have to fiddle. Exceptions will help with troubleshooting.
(Posted solution on behalf of the question author, to move it to the answer space).
Thanks to help/postings from generous forum contributors, below, I arrived at a working solution, below.
I included relatively full code/context, i.e., to enable others to arrive at the solution more quickly than I did.
aaa.bbb.ccc.CamelRestRoutes.java
package aaa.bbb.ccc;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
public class CamelRestRoutes extends RouteBuilder {
public CamelRestRoutes() {
}
#Override
public void configure() throws Exception {
restConfiguration().component("restlet")
.host("localhost")
.port(8182)
//.bindingMode(RestBindingMode.json_xml);
.bindingMode(RestBindingMode.json);
rest("/service")
//.bindingMode(RestBindingMode.json_xml)
.bindingMode(RestBindingMode.json)
.get("/getAll")
.produces("application/json")
.to("direct:thingX");
from("direct:thingX")
.to("bean:camelRestService?method=getAll")
.log("---------------------- (AAA) ----------------------> direct:thingX...:" + body().toString())
.to("direct:thingY");
from("direct:thingY")
.log("---------------------- (BBB) ----------------------> direct:thingY...:" + body().toString())
.to("direct:thingZ");
from("direct:thingZ")
.log("---------------------- (CCC) ----------------------> direct:thingZ...:" + body().toString())
.to("wmq:queue:mylocalqueue?jmsMessageType=Text&exchangePattern=InOnly");
}
}
aaa.bbb.ccc.CamelRestService.java
package aaa.bbb.ccc;
import aaa.bbb.ccc.model.CamelRestPojo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
#Path("/service/")
public class CamelRestService {
Map<Long, CamelRestPojo> itemMap = new HashMap<>();
public CamelRestService() {
init();
}
#GET
//#Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
#Produces({MediaType.APPLICATION_JSON})
#Path("/getAll/")
public Collection<CamelRestPojo> getAll() {
System.out.println("====================== (getAll) ---------------------->");
return itemMap.values();
}
final void init() {
System.out.println("---------------------- (init) ---------------------->");
CamelRestPojo o = new CamelRestPojo();
o.setName("JOE BLOW");
o.setId(100);
itemMap.put(o.getId(), o);
}
}
aaa.bbb.ccc.model.CamelRestPojo
package aaa.bbb.ccc.model;
import java.io.Serializable;
public class CamelRestPojo implements Serializable {
private long id;
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Override
public String toString() {
return "CamelRestPojo{" + "id=" + id + ", name=" + name + '}';
}
}
camel-route.xml
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
">
<camel:camelContext id="aaa.bbb.ccc.routing.poc" xmlns="http://camel.apache.org/schema/blueprint">
<packageScan>
<package>aaa.bbb.ccc</package>
</packageScan>
</camel:camelContext>
<bean id="camelRestService" class="aaa.bbb.ccc.CamelRestService"/>
<bean id="wmqcf" class="com.ibm.mq.jms.MQConnectionFactory">
<property name="hostName" value="localhost"/>
<property name="port" value="1414"/>
<property name="queueManager" value="QM1"/>
<property name="channel" value="DEV.ADMIN.SVRCONN"/>
<property name="transportType" value="1"/>
</bean>
<bean id="wmqcfw" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="wmqcf" />
<property name="username" value="admin" />
<property name="password" value="passw0rd" />
</bean>
<bean id="wmqcfg" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="wmqcfw"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="wmq" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="wmqcfg"/>
</bean>
</blueprint>
pom.xml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa.bbb.ccc</groupId>
<artifactId>camelRest</artifactId>
<version>1</version>
<packaging>bundle</packaging>
<name>camelRest</name>
<description>camelRest</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
<mq.version>8.0.0.7</mq.version>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.17.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>allclient</artifactId>
<version>${mq.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>jms</artifactId>
<version>${mq.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Export-Package>aaa.bbb.ccc*</Export-Package>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
here is the contents of the jboss fuse "deploy" folder
C:\tools\jboss-fuse-6.3.0.redhat-187\deploy>dir
Volume in drive C is OSDisk
Volume Serial Number is D89B-75DE
Directory of C:\tools\jboss-fuse-6.3.0.redhat-187\deploy
08/17/2017 01:49 PM <DIR> .
08/17/2017 01:49 PM <DIR> ..
08/17/2017 01:49 PM 7,975 camelRest-1.jar
06/29/2017 01:00 AM 159,649 com.ibm.mq.osgi.allclientprereqs_8.0.0.7.jar
06/29/2017 01:00 AM 8,011,749 com.ibm.mq.osgi.allclient_8.0.0.7.jar
06/29/2017 01:00 AM 4,088,715 com.ibm.mq.osgi.java_8.0.0.7.jar
06/29/2017 01:00 AM 171,064 com.ibm.msg.client.osgi.commonservices.j2se_8.0.0.7.jar
06/29/2017 01:00 AM 48,715 com.ibm.msg.client.osgi.jms.prereq_8.0.0.7.jar.DISABLE
06/29/2017 01:00 AM 639,807 com.ibm.msg.client.osgi.jms_8.0.0.7.jar
06/29/2017 01:00 AM 216,218 com.ibm.msg.client.osgi.nls_8.0.0.7.jar
06/29/2017 01:00 AM 279,861 com.ibm.msg.client.osgi.wmq.nls_8.0.0.7.jar
06/29/2017 01:00 AM 92,406 com.ibm.msg.client.osgi.wmq.prereq_8.0.0.7.jar
06/29/2017 01:00 AM 7,963,226 com.ibm.msg.client.osgi.wmq_8.0.0.7.jar
09/15/2016 04:19 AM 873 README
12 File(s) 21,680,258 bytes
2 Dir(s) 143,871,660,032 bytes free
C:\tools\jboss-fuse-6.3.0.redhat-187\deploy>
Other notes
For what it is worth, I had add following features:
-camel-jackson
-camel-restlet
(I'm sure your "mileage will vary" as you tinker to make your IBM MQ app work, etc).
Also, fwiw, running:
features:list | grep "jms"
yields:
JBossFuse:karaf#root> features:list | grep "jms"
[installed ] [2.4.0.redhat-630187 ] jms karaf-enterprise-2.4.0.redhat-630187 JMS service and commands
[installed ] [2.17.0.redhat-630187 ] camel-jms camel-2.17.0.redhat-630187
[uninstalled] [2.17.0.redhat-630187 ] camel-sjms camel-2.17.0.redhat-630187
[uninstalled] [3.1.5.redhat-630187 ] cxf-transports-jms cxf-3.1.5.redhat-630187
[uninstalled] [2.1.0.redhat-630187 ] switchyard-jms switchyard-2.1.0.redhat-630187
[uninstalled] [2.1.0.redhat-630187 ] switchyard-quickstart-bpel-jms-binding switchyard-2.1.0.redhat-630187
[uninstalled] [2.1.0.redhat-630187 ] switchyard-quickstart-camel-jms-binding switchyard-2.1.0.redhat-630187
[uninstalled] [2.1.0.redhat-630187 ] switchyard-demo-security-propagation-jms switchyard-2.1.0.redhat-630187
[uninstalled] [1.1 ] jms-spec activemq-core-5.11.0.redhat-630187 JMS spec 1.1 libraries
[installed ] [2.0 ] jms-spec activemq-core-5.11.0.redhat-630187 JMS spec 2.0 libraries
[uninstalled] [1.1 ] jms-spec-dep activemq-core-5.11.0.redhat-630187 JMS spec 1.1 dependency
[installed ] [2.0 ] jms-spec-dep activemq-core-5.11.0.redhat-630187 JMS spec 2.0 dependency
[uninstalled] [5.11.0.redhat-630187 ] activemq-jms-spec-dep activemq-core-5.11.0.redhat-630187 ActiveMQ broker libraries
[installed ] [3.2.16.RELEASE_1 ] spring-jms spring-2.4.0.redhat-630187 Spring 3.2.x JMS support

custom spring xd module with spring data elasticsearch: No qualifying bean of type [ElasticsearchTemplate] found

I customed a spring xd processor module,try link to elasticsearch in my module with spring data elasticsearch.
unittest is ok,but when deploy in the singlenode, throw the exception:
- Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.
config.TransformerFactoryBean#0': Cannot create inner bean 'com.eheluo.bigdata.wenxin.ToElasticsearch#0' of type [com.eh
eluo.bigdata.wenxin.ToElasticsearch] while setting bean property 'targetObject'; nested exception is org.springframework
.beans.factory.BeanCreationException: Error creating bean with name 'com.eheluo.bigdata.wenxin.ToElasticsearch#0': Injec
tion of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Coul
d not autowire field: private org.springframework.data.elasticsearch.core.ElasticsearchTemplate com.eheluo.bigdata.wenxi
n.ToElasticsearch.elasticsearchTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionExcep
tion: No qualifying bean of type [org.springframework.data.elasticsearch.core.ElasticsearchTemplate] found for dependenc
y: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.spr
ingframework.beans.factory.annotation.Autowired(required=true)}
it can't find bean org.springframework.data.elasticsearch.core.ElasticsearchTemplate.
my pom file is:
<parent>
<groupId>org.springframework.xd</groupId>
<artifactId>spring-xd-module-parent</artifactId>
<version>1.1.1.RELEASE</version>
<relativePath></relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>1.2.1.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
....
my custom module code is :
#Component
public class ToElasticsearch {
private Logger logger = Logger.getLogger(ToElasticsearch.class);
#Autowired
private ElasticsearchTemplate elasticsearchTemplate;
public String process(NewDataInterface data){
NewData newData = new NewData();
BeanUtils.copyProperties(data, newData);
String docid = elasticsearchTemplate.index(genIndexQuery(newData));
logger.debug("save to es");
return docid;
}
my application.properties is :
# options_class=com.eheluo.bigdata.wenxin.ToElasticsearch
# ELASTICSEARCH (ElasticsearchProperties})
# The cluster name (defaults to elasticsearch)
spring.data.elasticsearch.cluster-name=elasticsearch
# The address(es) of the server node (comma-separated; if not specified starts a client node)
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
# if spring data repository support is enabled
spring.data.elasticsearch.repositories.enabled=true
my module.properties has nothing to export options
my module.xml is :
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
">
<channel id="input"/>
<transformer input-channel="input" output-channel="output">
<beans:bean class="com.eheluo.bigdata.wenxin.ToElasticsearch" />
</transformer>
<channel id="output"/>
</beans:beans>
my unittest is :
public class ToElasticsearchTest {
private static SingleNodeApplication application;
private static int RECEIVE_TIMEOUT = 5000;
private static String moduleName = "toelasticsearch";
#BeforeClass
public static void setUp() {
RandomConfigurationSupport randomConfigSupport = new RandomConfigurationSupport();
application = new SingleNodeApplication().run();
SingleNodeIntegrationTestSupport singleNodeIntegrationTestSupport = new SingleNodeIntegrationTestSupport(application);
singleNodeIntegrationTestSupport.addModuleRegistry(new SingletonModuleRegistry(ModuleType.processor, moduleName));
}
#Test
public void test() {
String streamName = "toElasticsearchTest";
String newID = UUID.randomUUID().toString();
NewDataInterface newData = new NewDataPOJO();
newData.setsomthing("testtesttest");
newData.setId(newID);
Multiset<String> words = ConcurrentHashMultiset.create();
words.add("1");
words.add("2");
words.add("3");
words.add("4", 2);
newData.setsomthinx(words);
String processingChainUnderTest = moduleName;
SingleNodeProcessingChain chain = chain(application, streamName, processingChainUnderTest);
chain.sendPayload(newData);
String result = (String) chain.receivePayload(RECEIVE_TIMEOUT);
assertEquals(newID, result);
chain.destroy();
}
}
unit test is always ok:Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
but can't work in singlenode rutime.
why it can't find ElasticsearchTemplate in runtime?

Resources