it appears that the GA versions of
spring-core
spring-data-commons
spring-data-mongodb
as well as the most recent release candidate of
spring-boot-starter-web
spring-boot-autoconfigure
are not compatible.
what versions of these artifacts are compatible with each other?
I have a very basic Application.java that puts two objects into a MongoDB database and then takes them out and prints them to the screen.
import game.acorn.entities.Entity;
import game.acorn.mRepositoryInterfaces.EntityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class Application implements CommandLineRunner{
#Autowired
private EntityRepository repository;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
public void run(String... args) throws Exception {
repository.deleteAll();
repository.save(new Entity("Jack", "Skellington"));
repository.save(new Entity("Blake", "Yarbrough"));
System.out.println("Entities found");
for (Entity entity : repository.findAll()){
System.out.println(entity);
}
System.out.println();
System.out.println("Entity by first name 'Jack'");
System.out.println(repository.findByFirstName("Jack"));
System.out.println();
System.out.println("Entity by first name 'Blake'");
System.out.println(repository.findByFirstName("Blake"));
}
}
When I run this application with
spring-core version 4.0.2.RELEASE
spring-data-commons version 1.5.0.RELEASE
spring-boot-starter-web version 1.0.0.RC4
spring-data-mongodb version 1.4.1.RELEASE
spring-boot-autoconfigure version 1.0.0.RC3
I end up getting a java.lang.NoClassDefFoundError at
org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions
which looks like
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
final BeanDefinitionRegistry registry) {
new RepositoryConfigurationDelegate(getConfigurationSource(), this.resourceLoader)
.registerRepositoriesIn(registry, getRepositoryConfigurationExtension());
}
with
new RepositoryConfigurationDelegate(getConfigurationSource(), this.resourceLoader)
being the line 58. It seems that there is a discrepancy between the version I am using and spring-boot's dependency.
So I try to up version my spring-data-commons to version 1.7.0.RELEASE
and then the class becomes available but I then get a java.lang.NoSuchMethodError at
org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$1.<init>(AbstractRepositoryConfigurationSourceSupport.java:66)
which looks like
private AnnotationRepositoryConfigurationSource getConfigurationSource() {
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(
getConfiguration(), true);
return new AnnotationRepositoryConfigurationSource(metadata, getAnnotation(),
this.environment) {
#Override
public java.lang.Iterable<String> getBasePackages() {
return AbstractRepositoryConfigurationSourceSupport.this
.getBasePackages();
};
};
}
with
return new AnnotationRepositoryConfigurationSource(metadata, getAnnotation(),
this.environment) {
being lines 65-66.
when I check out
org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource
I find that the constructor
public AnnotationRepositoryConfigurationSource(AnnotationMetadata metadata, Class<? extends Annotation> annotation,
ResourceLoader resourceLoader, Environment environment) {
super(environment);
Assert.notNull(metadata);
Assert.notNull(annotation);
Assert.notNull(resourceLoader);
this.attributes = new AnnotationAttributes(metadata.getAnnotationAttributes(annotation.getName()));
this.metadata = metadata;
this.resourceLoader = resourceLoader;
}
expects one more argument than AbstractRepositoryConfigurationSourceSupport in spring-boot-autoconfigure gives it.
So, my question is, what versions of
spring-core
spring-data-commons
spring-boot-starter-web
spring-data-mongodb
spring-boot-autoconfigure
are compatible with each other?
my pom looks like
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.0.RC3</version>
</parent>
<groupId>Master-Project</groupId>
<artifactId>Master-Project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>Master Project for MongoDB and Spring</description>
<modules>
</modules>
<dependencies>
<!-- Spring Stuff -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.0.0.RC3</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!--
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.3</source>
<target>1.1</target>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugin</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I remove the version tags on the dependencies I get the same no such method exception.
This is fixed if you use the Spring Boot dependencies pom (or the starter parent) with 1.0.0.RC5 or better.
Related
I have created a Kinesis Analytics Streaming Application in SpringBoot which will consume messages from the AmazonKinesis input stream and will do some operations on top of it using the Apache Flink DataStream library.
When, I am uploading the application jar to S3 and trying to run this application on Streaming App it is throwing ClassNotFoundException for one of the files which is the ApplicationConfiguration file. Also, when I am running this application locally, it is running fine without any errors and I am able to consume the messages.
Below are some of the code files.
ApplicationConfiguration.java
import java.util.Properties;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer;
import org.apache.flink.streaming.connectors.kinesis.FlinkKinesisProducer;
import org.apache.flink.streaming.connectors.kinesis.config.ConsumerConfigConstants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
public class ApplicationConfiguration {
#Value("${oe.metric.input.stream}")
private String inputStreamName;
#Value("${oe.metric.output.stream}")
private String outputStreamName;
#Value("${aws.region}")
private String region;
#Value("${stream.initial.position}")
private String position;
#Bean
public FlinkKinesisProducer<String> createSinkFromStaticConfig() {
Properties outputProperties = new Properties();
outputProperties.setProperty(ConsumerConfigConstants.AWS_REGION, region);
outputProperties.setProperty("AggregationEnabled", "false");
FlinkKinesisProducer<String> sink = new FlinkKinesisProducer<>(new SimpleStringSchema(),
outputProperties);
sink.setDefaultStream(outputStreamName);
sink.setDefaultPartition("0");
return sink;
}
#Bean
public DataStream<String> createSourceFromConfig() {
Properties inputProperties = new Properties();
inputProperties.setProperty(ConsumerConfigConstants.AWS_REGION, region);
inputProperties.setProperty(ConsumerConfigConstants.STREAM_INITIAL_POSITION, position);
return ApplicationConstants.streamExecutionEnvironment.addSource(
new FlinkKinesisConsumer<>(inputStreamName, new SimpleStringSchema(), inputProperties));
}
Error:
Caused by: java.lang.IllegalStateException: Cannot load configuration class: com.pkg.config.ApplicationConfiguration
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:415)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:268)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:325)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:147)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.pkg.KinesisConsumerApplication.main(KinesisConsumerApplication.java:18)
... 25 more
Caused by: java.lang.ClassNotFoundException: com.pkg.config.ApplicationConfiguration
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
KinesisConsumerApplication.java
#SpringBootApplication
#EnableAutoConfiguration
#ComponentScan(basePackages = "com.pkg")
public class KinesisConsumerApplication implements CommandLineRunner {
#Autowired
ApplicationContext ctx;
public static void main(String[] args) {
SpringApplication.run(KinesisConsumerApplication.class, args);
}
#Override
public void run(String... args) throws Exception {
GetKinesisRecords getKinesisRecords = ctx.getBean(GetKinesisRecords.class);
getKinesisRecords.getDataFromStream();
}
}
Maven pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>kinesis-consumer</artifactId>
<build>
<plugins>
<plugin>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<artifactId>lombok</artifactId>
<groupId>org.projectlombok</groupId>
</exclude>
</excludes>
</configuration>
<groupId>org.springframework.boot</groupId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<artifactId>spring-boot-starter</artifactId>
<groupId>org.springframework.boot</groupId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>flink-connector-kinesis_${scala.binary.version}</artifactId>
<groupId>org.apache.flink</groupId>
<version>1.13.2</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
<version>1.13.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<artifactId>flink-core</artifactId>
<groupId>org.apache.flink</groupId>
<version>1.13.2</version>
</dependency>
<dependency>
<artifactId>jackson-datatype-jsr310</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
</dependency>
<dependency>
<artifactId>spring-boot-starter-test</artifactId>
<groupId>org.springframework.boot</groupId>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>ssai-common</artifactId>
<groupId>com.adsparx.phoenix</groupId>
<version>1.2.0</version>
</dependency>
<dependency>
<artifactId>flink-clients</artifactId>
<groupId>org.apache.flink</groupId>
<version>1.15.0</version>
</dependency>
<dependency>
<artifactId>jakarta.xml.bind-api</artifactId>
<groupId>jakarta.xml.bind</groupId>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
</dependencies>
<description>Apache Kinesis Consumer</description>
<groupId>com.pkg</groupId>
<modelVersion>4.0.0</modelVersion>
<name>kinesis-consumer</name>
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<relativePath/>
<version>2.4.0</version>
</parent>
<properties>
<java.version>11</java.version>
<scala.binary.version>2.12</scala.binary.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<version>0.0.1-SNAPSHOT</version>
</project>
Things that I have tried on my end:
Clean build the project a couple of times.
Checked Java and Spring version in pom, as suggested in one of the
StackOverflow post.
Downgraded SpringBoot version from "2.7.0" to "2.4.0".
Added ComponentScan annotation in main class.
Tried changing the annotation from #Configuration to #Component.
Last but not least, tried google and stackoverflow.
Can someone please help me identify the error?
Is this because you're attempting to use dependencies for flink 1.15? AFAIK, 1.13 is the latest version supported. You need to choose which flink version you intend to use when creating the streaming application.
I'm currently trying to set up automated testing for a Maven project, but I've run into a problem. When running my tests using mvn test, I get the following result:
-------------------------------------------------------------------------------
Test set: no.digipat.patornat.servlets.ServletTests
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.398 s <<< FAILURE! - in no.digipat.patornat.servlets.ServletTests
no.digipat.patornat.servlets.ServletTests Time elapsed: 0.368 s <<< ERROR!
java.lang.NoClassDefFoundError: com/mongodb/OperationExecutor
Caused by: java.lang.ClassNotFoundException: com.mongodb.OperationExecutor
I get the same error when running the tests in Eclipse.
This is my pom.xml:
<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>no.digipat.patornat</groupId>
<artifactId>backend</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Pat or Nat Backend</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<repositories>
<repository>
<id>cytomine-uliege-Cytomine-java-client</id>
<url>https://packagecloud.io/cytomine-uliege/Cytomine-java-client/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lordofthejars</groupId>
<artifactId>nosqlunit-mongodb</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.fakemongo</groupId>
<artifactId>fongo</artifactId>
<version>2.2.0-RC2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>be.cytomine.client</groupId>
<artifactId>cytomine-java-client</artifactId>
<version>2.0.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<includes>
<include>ServletTests.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
The relevant Java files:
ServletTests.java:
package no.digipat.patornat.servlets;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import static com.lordofthejars.nosqlunit.mongodb.InMemoryMongoDb.InMemoryMongoRuleBuilder.newInMemoryMongoDbRule;
#RunWith(Suite.class)
#SuiteClasses({MyTest.class})
public class ServletTests {
private static final EnvironmentVariables environmentVariables = new EnvironmentVariables();
#ClassRule
public static final TestRule chain = RuleChain
.outerRule(newInMemoryMongoDbRule().build())
.around(environmentVariables);
#BeforeClass
public static void setUpClass() {
environmentVariables.set("MY_VARIABLE", "some value");
}
}
MyTest.java:
package no.digipat.patornat.servlets;
import static org.junit.Assert.*;
import org.junit.Test;
public class MyTest {
#Test
public void test() {
fail("Not yet implemented");
}
}
Any ideas on how to solve this? I tried running mvn clean (which previously helped me fix a similar issue), but to no avail.
I think you need the maven-compiler-plugin in your pom.xml
<build>
<!-- put here the path of your test source directory -->
<testSourceDirectory>src/test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
...
It seems that the issue was that the latest versions of Fongo and mongo-java-driver are incompatible. When I change the dependencies of Fongo and/or the Mongo Java driver to older versions (I specifically tried versions 2.1.0 and 3.6.3, respectively), the error disappears. However, since this solution seems rather fragile and inflexible, the best bet is probably to switch to an alternative to Fongo. According to this GitHub comment, mongo-java-server could be a good option. A perhaps more robust alternative, and the one I'll probably end up using, is to use a "real" test database. This article has information about a couple of ways to do this.
When I try to deploy my .war project (Spring Boot) on a Tomcat server I get the following exception on the logs. Note that this exception doesn't happen locally, so I can only reproduce it on server enviroment.
Complete stacktrace https://pastebin.com/8uFqwk0U
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingComponent': Failed to introspect bean class [com.project.components.MappingComponent] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: java/time/temporal/Temporal
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:269) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
I searched of course about this issue and I've changed some dependencies on ton pom.xml, also removed and added constructors just in case but I couldn't figure out why this is happening.
MappingComponent the calss that exception happens
#Component
public class MappingComponent {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
#Autowired
Repository1 repo1;
#Autowired
Repository2 repo2;
//no constructors
//methods that are using the repositories
}
MappingController the class that injects MappingComponent
#RestController
#CrossOrigin
#RequestMapping("/services")
public class MappingController {
#Autowired
private ClientComponent clientComponent;
#Autowired
private MappingComponent mappingComponent;
//no constructors
//services that are using the components
}
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>services</groupId>
<artifactId>services</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>services</name>
<description>Services</description>
<packaging>war</packaging>
<properties>
<java.version>1.7</java.version>
</properties>
<dependencies>
<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-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Main class
#SpringBootApplication
public class ServicesApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ServicesApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(ServicesApplication.class, args);
}
}
I am aware that both java and spring are outdated, but it doesn't depend on me to upgrade them to a newer version. And that's not the issue because there are other services deployed with the same version (and identical pom.xml).
Temporal class has been introduced only in 1.8 and in your pom I see that you use 1.7.
When you are not sure of when a class has been introduced, just check in the Javadoc the #Since tag.
You might need to external the external dependency jar into the lib directory of the Tomcat web server. First shutdown tomcat, add jar to the lib directory, and then startup tomcat.
I am trying to deploy a spring boot application as a WAR to a tomcat server. I can build and deploy the war to the tomcat server just fine. When I start the server though my spring application never runs. The server starts up just fine. I have done everything Spring says to do here,
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
My project has its own custom Parent POM and consists of 2 modules.
I have read several other similar threads and as far as I can tell I have everything set up properly but clearly something is wrong. Any help would be much appreciated.
THank You!
Parent pom
<groupId>com.project</groupId>
<artifactId>TelematicsNotificationSystem</artifactId>
<name>TelematicsNotificationSystem</name>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
<artifact-deployer.version>2.0.0-RELEASE</artifact-deployer.version>
<cxf.version>2.5.2</cxf.version>
<start-class>com.project.TNS.TelematicsNotificationSystem</start-class>
</properties>
<modules>
<module>TelematicsNotificationSystem-wsclient</module>
<module>TelematicsNotificationSystem-web</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
</dependencies>
Web Project Pom
<artifactId>TelematicsNotificationSystem-Web</artifactId>
<name>TelematicsNotificationSystem-Web</name>
<packaging>war</packaging>
<parent>
<groupId>com.project</groupId>
<artifactId>TelematicsNotificationSystem</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<properties>
<start-class>com.project.TNS.TelematicsNotificationSystem</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources/</directory>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
My Application Class
package TNS;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
#SpringBootApplication
public class TelematicsNotificationSystem extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(TelematicsNotificationSystem.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TelematicsNotificationSystem.class);
}
}
Remember to refresh the application once deployed in Tomcat. It may be working well and only a refresh is needed.
Although I agree with Deinum that I needed to clean up my Pom that was not the overall fix. The fix was to simply add a component scan to my class which contained my main method.
#SpringBootApplication
#ComponentScan(basePackageClasses = DashBoardController.class)
public class TelematicsNotificationSystem extends SpringBootServletInitializer
The starting app couldn't find the Controller so it could handle any of my mapping requests.
I'm trying to implement a custom mediator for WSO2 ESB (4.5.1) using its own XML configuration. I'm able to use the mediator just fine as a class mediator with the following config:
<class name="test.synapse.mediator.TestMediator"/>
However, what I'm trying to achieve is being able to call the mediator with a syntax like this:
<t:TestMediator xmlns:t="test:mediator" />
Having followed the available help on the matter for WSO2 ESB to the letter, I'm getting the following error as I try to create a proxy using the mediator with its own XML config:
ERROR - MediatorFactoryFinder Unknown mediator referenced by configuration element : {test:mediator}TestMediator
Needless to say, I've written the two text files containing the fully qualified class names of the mediator factory and serializer classes respectively and placed them in the META-INF/services directory in the bundle jar file.
This is the source code for my mediator class:
package test.synapse.mediator;
import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
public class TestMediator extends AbstractMediator {
public boolean mediate(MessageContext context) {
System.out.println("TestMediator mediating!");
return true;
}
}
Here's the code for my mediator factory:
package test.synapse.mediator;
import java.util.Properties;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
import org.apache.synapse.Mediator;
import org.apache.synapse.config.xml.MediatorFactory;
public class TestMediatorFactory implements MediatorFactory {
public static final QName QNAME = new QName("test:mediator", "TestMediator");
#Override
public Mediator createMediator(OMElement omElement, Properties properties) {
return new TestMediator();
}
#Override
public QName getTagQName() {
return QNAME;
}
}
And the following is the code for my mediator serializer:
package test.synapse.mediator;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.synapse.Mediator;
import org.apache.synapse.config.xml.MediatorSerializer;
public class TestMediatorSerializer implements MediatorSerializer {
public static final String MEDIATOR_CLASS_NAME = TestMediator.class.getName();
#Override
public String getMediatorClassName() {
return MEDIATOR_CLASS_NAME;
}
#Override
public OMElement serializeMediator(OMElement parent, Mediator mediator) {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMElement element = factory.createOMElement(TestMediatorFactory.QNAME);
parent.addChild(element);
return element;
}
}
And finally, the somewhat lengthy content of the project's pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>test.synapse.mediator.TestMediator</groupId>
<artifactId>TestMediator</artifactId>
<version>1.0.0</version>
<packaging>bundle</packaging>
<name>TestMediator</name>
<description>TestMediator</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>TestMediator</Bundle-SymbolicName>
<Bundle-Name>TestMediator</Bundle-Name>
<Bundle-ClassPath>.</Bundle-ClassPath>
<Export-Package>test.synapse.mediator</Export-Package>
<Import-Package>*; resolution:=optional</Import-Package>
<Fragment-Host>synapse-core</Fragment-Host>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<buildcommands>
<buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
</buildcommands>
<projectnatures>
<projectnature>org.wso2.developerstudio.eclipse.artifact.mediator.project.nature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
</projectnatures>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources/services</directory>
<targetPath>META-INF/services</targetPath>
</resource>
</resources>
</build>
<repositories>
<repository>
<releases>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>commons-httpclient.wso2</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1.0.wso2v2</version>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4.0.wso2v1</version>
</dependency>
<dependency>
<groupId>org.apache.synapse</groupId>
<artifactId>synapse-core</artifactId>
<version>2.1.0-wso2v7</version>
</dependency>
<dependency>
<groupId>wsdl4j.wso2</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2.wso2v4</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.schema.wso2</groupId>
<artifactId>XmlSchema</artifactId>
<version>1.4.7.wso2v2</version>
</dependency>
<dependency>
<groupId>org.apache.abdera.wso2</groupId>
<artifactId>abdera</artifactId>
<version>1.0.0.wso2v3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs.wso2</groupId>
<artifactId>geronimo-stax-api_1.0_spec</artifactId>
<version>1.0.1.wso2v2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.wso2</groupId>
<artifactId>httpcore</artifactId>
<version>4.1.0-wso2v1</version>
</dependency>
<dependency>
<groupId>org.apache.neethi.wso2</groupId>
<artifactId>neethi</artifactId>
<version>2.0.4.wso2v4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2.wso2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.1.wso2v6</version>
</dependency>
<dependency>
<groupId>org.apache.woden.wso2</groupId>
<artifactId>woden</artifactId>
<version>1.0.0.M8-wso2v1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
<artifactId>axiom</artifactId>
<version>1.2.11.wso2v3</version>
</dependency>
<dependency>
<groupId>commons-io.wso2</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.0.wso2v2</version>
</dependency>
</dependencies>
<properties>
<CApp.type>lib/synapse/mediator</CApp.type>
</properties>
</project>
I've been experimenting for a long time changing various aspects of the pom-file and the code. I've come to notice, that I can call the mediator using the class-mediator if I leave out the Fragment-Host part of the configuration. If the Fragment-Host element is present, neither way of calling the mediator works.
As expected I'm using apache Maven to build a jar-file of the project. I'm dropping the jar to the <ESB_HOME>/repository/components/dropins-directory.
I've tried using WSO2 ESB 4.5.1 and 4.7.0 with the exact same results.
What must I change to get the custom XML configuration to work?
Any input would be greatly appreciated!
Attachments:
Zipped source at Dropbox: TestMediator.zip
Jar built using maven at Dropbox: TestMediator-1.0.0.jar
Seeing as there apparently is some bug in the WSO2 ESB itself, which causes the bundle containing the mediator and its factory and serializer not to get loaded in the case that its manifest contains a Fragment-Host definition I went for a slightly more complicated scenario to get my mediator to function using custom XML config.
Having used an activator class in the bundle to confirm that it doesn't get loaded it occurred to me that I could also use the activator to manually register the MediatorFactory and MediatorSerializer classes in the ESB.
I did this by writing the following activator for my OSGI bundle:
package test;
import java.text.MessageFormat;
import java.util.Map;
import org.apache.synapse.config.xml.MediatorFactoryFinder;
import org.apache.synapse.config.xml.MediatorSerializer;
import org.apache.synapse.config.xml.MediatorSerializerFinder;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import test.synapse.mediator.TestMediator;
import test.synapse.mediator.TestMediatorFactory;
import test.synapse.mediator.TestMediatorSerializer;
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
{
Map<javax.xml.namespace.QName, java.lang.Class> mediatorFactoryMap = MediatorFactoryFinder.getInstance().getFactoryMap();
mediatorFactoryMap.put(TestMediatorFactory.QNAME, TestMediatorFactory.class);
}
{
Map<String, MediatorSerializer> mediatorSerializerMap = MediatorSerializerFinder.getInstance().getSerializerMap();
mediatorSerializerMap.put(TestMediator.class.getName(), TestMediatorSerializer.class.newInstance());
}
}
public void stop(BundleContext context) throws Exception {
// Maybe undo what was done in the start(BundleContext) method..?
System.out.println(this.getClass().getName() + ".stop(BundleContext) called");
}
}
Obviously the Activator class needs to be defined to be the activator for the bundle. This is done by adding the following node to the pom.xml bundle plugin configuration under the Instructions element:
<Bundle-Activator>test.Activator</Bundle-Activator>
Using this manual way of registering the factory and serializer classes the org.apache.synapse.config.xml.MediatorFactory and org.apache.synapse.config.xml.MediatorSerializer files are not needed and can be removed from the final jar.
Additionally the Fragment-Host element needs to be removed from the same parent node to actually have the activator class' start method get called.
Also the osgi core dependency containing the BundleActivator interface needs to be added.
By doing that we're left with the following complete pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>test.synapse.mediator.TestMediator</groupId>
<artifactId>TestMediator</artifactId>
<version>1.0.0</version>
<packaging>bundle</packaging>
<name>TestMediator</name>
<description>TestMediator</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>TestMediator</Bundle-SymbolicName>
<Bundle-Name>TestMediator</Bundle-Name>
<Bundle-ClassPath>.</Bundle-ClassPath>
<Bundle-Activator>test.Activator</Bundle-Activator>
<Export-Package>test.synapse.mediator</Export-Package>
<Import-Package>*; resolution:=optional</Import-Package>
<!-- <Fragment-Host>synapse-core</Fragment-Host> -->
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<buildcommands>
<buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
</buildcommands>
<projectnatures>
<projectnature>org.wso2.developerstudio.eclipse.artifact.mediator.project.nature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
</projectnatures>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<releases>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<id>wso2-nexus</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>commons-httpclient.wso2</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1.0.wso2v2</version>
</dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4.0.wso2v1</version>
</dependency>
<dependency>
<groupId>org.apache.synapse</groupId>
<artifactId>synapse-core</artifactId>
<version>2.1.0-wso2v7</version>
</dependency>
<dependency>
<groupId>wsdl4j.wso2</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2.wso2v4</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.schema.wso2</groupId>
<artifactId>XmlSchema</artifactId>
<version>1.4.7.wso2v2</version>
</dependency>
<dependency>
<groupId>org.apache.abdera.wso2</groupId>
<artifactId>abdera</artifactId>
<version>1.0.0.wso2v3</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs.wso2</groupId>
<artifactId>geronimo-stax-api_1.0_spec</artifactId>
<version>1.0.1.wso2v2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.wso2</groupId>
<artifactId>httpcore</artifactId>
<version>4.1.0-wso2v1</version>
</dependency>
<dependency>
<groupId>org.apache.neethi.wso2</groupId>
<artifactId>neethi</artifactId>
<version>2.0.4.wso2v4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2.wso2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.1.wso2v6</version>
</dependency>
<dependency>
<groupId>org.apache.woden.wso2</groupId>
<artifactId>woden</artifactId>
<version>1.0.0.M8-wso2v1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
<artifactId>axiom</artifactId>
<version>1.2.11.wso2v3</version>
</dependency>
<dependency>
<groupId>commons-io.wso2</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.0.wso2v2</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
<properties>
<CApp.type>lib/synapse/mediator</CApp.type>
</properties>
</project>
Having done these modifications and dropping the Maven built jar to the /repository/components/dropins directory the mediator finally works with its custom configuration.
I've zipped the complete final project source code. That archive also is available on Dropbox: TestMediator-final.zip
Edit
Upon additional experimentation it became apparent that the above approach doesn't work in WSO2 ESB 4.5.1, which is the platform I was originally trying to get this to work on. The code performs as expected in WSO2 4.7.0.
I haven't been able to get WSO2 ESB 4.5.1 (or 4.6.0) to call the activator's start(BundleContext) method no matter what I've tried.