Edit: Found a solution, I will update this post
Edit 2: The problem was that I defined my Commands and Events inside the src folder of my first and second microservice. The first microservice shot a com.myApplication.PaymentManagementService.commands.ApproveOrderCommand-command, while the command handler in the second microservice expected a com.myApplication.OrderManagementService.commands.ApproveOrderCommand-command.
I fixed the redundancy by lifting the commands and events a few hierarchy levels into a common api-folder that both services can access. Now the second micoservice expects a com.myApplication.api.commands.ApproveOrderCommand, that the first microservice shoots.
That solution may sound trivial to some, but since this is not described anywhere in the documentation and I didn't expect the name of the path to be relevant in handling the commands and events, you have to figure that out first.
Original post:
I'm currently implementing a distributed command bus with spring cloud. I followed the below example exactly, but I'm getting the following issues in both of my (Client-)Microservices.
https://docs.axoniq.io/reference-guide/v/master/extensions/spring-cloud
1. Could not auto-wire. There is more than one Bean of "Registration" type.
Screenshot 1
2. Cannot find a bean with the qualifier "localSegment", even though I'm using Spring Auto Configuration.
Screenshot 2
I can start both the client-applications (this one and the other microservice) nevertheless.
But:
I can't send a command from the first Microservice to the second Microservice, the following error appears:
org.axonframework.commandhandling.NoHandlerForCommandException: No
node known to accept
[com.myApplication.PaymentManagementService.commands.CheckPaymentCommand]
Both microservices are registered to my eureka server.
In the first Microservice, I produce a command over a REST Endpoint, the Command fires outside of an Aggegrate (via commandGateway.send()).
In the second Microservice, I want to receive the command:
#Component
public class TestCommandHandler {
#CommandHandler
public void handle(ApproveOrderCommand command){
System.out.println("Command delivered!");
}
}
Is there anything wrong with my dependencies or application properties? Do I have to setup a saga for this to work?
One of my poms:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.myApplication</groupId>
<artifactId>PaymentManagementService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PaymentManagementService</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Axon -->
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-spring-boot-starter</artifactId>
<version>4.4.5</version>
<!--
<exclusions>
<exclusion>
<groupId>org.axonframework</groupId>
<artifactId>axon-server-connector</artifactId>
</exclusion>
</exclusions>
-->
</dependency>
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-spring-boot-autoconfigure</artifactId>
<version>4.4.5</version>
</dependency>
<!-- Spring Cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.axonframework.extensions.springcloud</groupId>
<artifactId>axon-springcloud-spring-boot-starter</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>
application.properties of Microservice 1
Properties_Microservice_1
application.properties of Microservice 2
Properties_Microservice_2
I'm glad that you found out the solution by yourself.
Hope that you discovered our sample project https://github.com/AxonFramework/extension-springcloud-sample . This is a good starting point.
It also contain some indication on dependency and version that your project should have.
We also have the refguide that is a must read https://docs.axoniq.io/reference-guide/extensions/spring-cloud
Looking at your pom file is not clear to me if you are or you are not using axon server. If not, I can suggest to uncomment the exclusion of axon-server-connector dependency.
Related
I am trying to build an application with a embedded HSQL Database.
I am using Spring Boot 2.7.2, Hibernate 6.1.0-Final, Hibernate-Core Version 5.6.10-Final and HSQL 2.7.0 with Java 18.
For this, I've done alot of research for the error, even here on stack overflow, but somehow, none of them works.
First off, here's my 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>2.7.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.bloise</groupId>
<artifactId>skt</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hsql.version>2.7.0</hsql.version>
<hibernate.version>6.1.0.Final</hibernate.version>
<hibernate.core.version>5.6.10.Final</hibernate.core.version>
</properties>
<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsql.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.core.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.6.10.Final</version>
</dependency>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${project.parent.version}</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Then, I'm using currently following applications.properties:
# ===============================
# = SERVER
# ===============================
server.port= 9050
# HIBERNATE
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.HSQLDialect
spring.jackson.serialization.fail-on-empty-beans=false
# Naming strategy
#spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
#spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
# Database
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
spring.datasource.url=jdbc:hsqldb:hsql://localhost/testdb
spring.datasource.username=sa
spring.datasource.password=
So, for what I've tried, was to remove the datasource.url (as read somewhere here on stackoverflow), but the error popped up.
Then I found a way to use "hsql-config.xml" (with some configuration) and use it at my spring-boot entry point with
#ImportResource(value="classpath:/hsql-config.xml")
But it did not help.
Any ideas on how to make this work? I've looked up several tutorials accross the internet, it seems that non of those brought a solution.
Your database URL accesses a separate HSQLDB server instance, which should be started before your application, and is similar to a PostgreSQL or MySQL server.
spring.datasource.url=jdbc:hsqldb:hsql://localhost/testdb
If you don't want to rely on a separate server, you can use a file: database URL, which opens the database directly from your application. For example:
spring.datasource.url=jdbc:hsqldb:file:C:/dbfiles/testdb
There are two options. the first one is to start HSQLDB as a standalone not embedded server. the second one is to make the datasource bean depends on the loading properties bean such as this first answer: Has HSQLDB some mechanism to save in-memory data to file? using #DependsOn annotation.
Im try to create a simple project with 2 application ( a simple rest app and a config-server app )
My config-server project is ok, because if I got http://localhost:9091/form-create/container I can see all vars from form-create.properties
but my application form-create is not getting properties from config-server
here is my bootstrap.properties in form-create project
spring.application.name=form-create
spring.cloud.config.uri=http://localhost:9091
spring.cloud.config.fail-fast=true
pom.xml in form-create project
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath />
</parent>
<groupId>com.formcloud</groupId>
<artifactId>ms-form-create</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ms-form-create</name>
<description>Microservice to manage form creation</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Main class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class MsFormCreateApplication {
public static void main(String[] args) {
SpringApplication.run(MsFormCreateApplication.class, args);
}
}
What am I doing wrong? if I start my form-create application is starting on 8080 port and not getting properties from config server.
I think you should try to check two things:
Your maven dependencies. It looks like you've put them wrong, namely, if you're running cloud config client, why do you have a dependency for spring-cloud-config-server?
For Web and cloud config client the following list is sufficient:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
When you start the config server, are you sure that it indeed reads the configuration from the repository you've configured (git, file system, whatever)?
In general it exposes REST API so you can curl the server to get the information even without starting the spring boot application
Try that and make sure that it works as expected. For example, read this part of tutorial. Note that you might have put the configuration for different profile or different branch, cloud config server can handle that, but you'll have to specify profile for example in the bootstrap.properties.
My Spring boot 2.0.3 web app runs fine on Eclipse, with Java 1.8-1.4.1 and the embedded Tomcat. But when I build my war file (using mvn package) and deploy it to linux (uname -mrs gives Linux 4.9.77-31.58.amzn1.x86_64 x86_64), and run it ( same java version) on a external Tomcat 9.0.10, the JVM crashes when it connects to Oracle. The code where the crash occurs is:
#Repository
public class ReadFromDb {
#Autowired
private NamedParameterJdbcTemplate jdbcTemplate;
public TspsPatent readTspsPatent(TspsPatent tspsPatent)
{
System.out.println("DSxxx1");
// Next line crashes
List<TspsPatent> tspsPatents = jdbcTemplate.query("select 3 patent_sk from dual",
(rs, rowNum) -> new TspsPatent (rs.getString("patent_sk")));
System.out.println("DSxxx2");
if (tspsPatents.size() == 0) {return null;}
return tspsPatents.get(0);
}
}
ie the DSxxx1 line is printed in catalina.out, but DSxxx2 isn't.
The full catalina.out is here:
catalina.out
If examine the jni connections using:
-Xcheck:jni
in setenv.sh, then in catalina.out I get:
catalina-jni.out
When the JVM crashes it creates a log file hs_err_pid40342.log, which is here:
hs_err_pid40342.log
This log file contains , on lines 508 - 518 a group of java/lang/ClassNotFoundException one of which is:
Event: 18.567 Thread 0x00007fe844620000 Exception <a 'java/lang/ClassNotFoundException': com/clarivate/dataviewer/model/TspsPatentCustomizer> (0x000000059e3dd210) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u141/9370/hotspot/src/share/vm/classfile/systemDictionary.cpp, line 210]
I wrote the package:
com/clarivate/dataviewer/model
but there is no class called TspsPatentCustomizer
I have 2 classes with similar names in this package:
TspsPatent and TspsPatentNumberChange
but they are both just plain pojo's.
Why is the JVM looking for a class called TspsPatentCustomizer when this class has never existed?
The NamedParameterJdbcTemplate class handles the dB connections. It is in :
spring-jdbc-5.0.7.RELEASE.jar
and this jar is in my war file
My application.properties has:
logging.level.root=INFO
server.port=8090
server.servlet.path=/
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.datasource.initialization-mode=always
spring.datasource.url=jdbc:oracle:oci:#myDataBase
spring.datasource.username=myUser
spring.datasource.password=myPassword
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
My pom.xml file contains:
<?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.clarivate</groupId>
<artifactId>dataviewer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>DataViewer</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>com.clarivate.dataviewer.DvMain</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- DS may need to remove for tomcat installation -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
</dependencies>
<!-- Required to find ojdbc6, because Oracle don't make it available to maven-->
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
<build>
<finalName>DataViewer</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- <mainClass>com.clarivate.dataviewer.DvMain</mainClass>-->
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
<description>TSPS data viewer</description>
One query is this dependency:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.1.0</version>
</dependency>
My $ORACLE_HOME is not part of my war file, it's on linux at:
/oracle/app/oracle/product/11.2.0/client_1
which can't be changed.
So the version numbers are slightly different, does this make a difference and if so how do I change my maven version?
The strange TspsPatentConversion reference is a sideline, my main concern is to get the app running. Have I missed out any Oracle related settings or dependencies?
Any help or suggestions greatly appreciated
The answer was slightly mismatched version in the Oracle client see:
Oracle community
In my war file I had ojdbc6-11.2.0.1.0.jar, my Oracle client in $ORACLE_HOME on Linux was 11.2.0, these 2 versions are not identical and this incompatability caused the jvm crash. The solution was to remove ojdbc6-11.2.0.1.0.jar from the war to force my app to use ojdbc6.jar in $ORACLE_HOME. To do this you add ojdbc6 scope "provided" to the pom.
I have a maven project with jdk: 1.8, spring-boot: 1.5.4.RELEASE, spring: 4.3.9.RELEASE, and some vendor dependencies. The project builds and runs but when I access resources used by vendor packages, I get following exception:
java.lang.NoSuchMethodError: org.apache.log4j.ConsoleAppender.<init>(Lorg/apache/log4j/Layout;)V
at bkLogPkg.SingletonLog.<init>(SingletonLog.java:19) ~[VendorComLib.jar:na]
at Vendor.ConnectionBasket.<init>(ConnectionBasket.java:31) ~[VendorServices.jar:na]
at Vendor.ConnectionBasketInterface.Loader(ConnectionBasketInterface.java:450) ~[VendorServices.jar:na]
at Vendor.ConnectionBasketInterface.<init>(ConnectionBasketInterface.java:251) ~[VendorServices.jar:na]
...
It's trying to call method from Vendor jar file to log4j 1.2.14.jar file, but it's unable to do it. I have added vendor dependencies in pom.xml file.
pom.xml:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.sample</groupId>
<artifactId>angular2-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>angular2-spring</name>
<description>Angular 2 application with Spring 4</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<org.slf4j-version>1.2.14</org.slf4j-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-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- Vendor dependencies from Local Repository -->
<dependency>
<groupId>Vendor</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorServiceAuth</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorServices</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorComLib</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorHeaderClass</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I have the same issue today. It cost me several hours to find the reason.
You just have a conflict with your log4j jar.
The quick fix for this is :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
If you really need log4j, then add the dependency:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
You can check log4j-over-slf4j to know the detail.
I have encountered similar issues and all of mine were solved by making sure the version I was using was the most updated and that is is compatible with the rest of the code. With your problem, it looks as if the .jar is specifically built to be compatible so I doubt that's the issue. Only things I can think of given the information at hand is:
1.) Try making sure all .jar's being used are newest version. (Sometimes if your other .jar's are not completely updated, they can throw errors/exceptions when trying to access a method from a .jar that is a version ahead.)
2.) If "1" doesn't do it, try using a dependency import function in an IDE. I have had many occurrences where Maven was just causing odd errors from IDE compatibility. Importing all .jar's from a "Dependency" menu could also help.
I am trying to deploy spring boot application on my server. I have kept my WAR file on webapps folder inside Tomcat.
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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.privilance</groupId>
<artifactId>privilance_survey</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>privilance_survey</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j</artifactId>
<version>2.1</version>
</dependency>
<!--
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.21</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.11</version>
</dependency>
</dependencies>
<build>
<finalName>privilance</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I did some search and find out some people solved their problem by adding this bean.
#Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory() {
#Override
protected void postProcessContext(Context context) {
final int cacheSize = 40 * 1024;
StandardRoot standardRoot = new StandardRoot(context);
standardRoot.setCacheMaxSize(cacheSize);
context.setResources(standardRoot); // This is what made it work in my case.
logger.info(String.format("New cache size (KB): %d", context.getResources().getCacheMaxSize()));
}
};
return tomcatFactory;
}
But in my case this is also not working. Whenever I run localhost:8080/privilance on my browser says:
The origin server did not find a current representation for the target
resource or is not willing to disclose that one exists.
and in my cmd prompt says:
the background cache eviction process was unable to free [10] percent
of the cache for context. consider increasing maximum size of the
cache ....approximately [9285] kb of data remained on the cache.
There are multiple solutions:
Increase cache (recommended)
Lower the TTL (not recommended)
Suppress cache log warnings (not recommended)
Disable cache
more details on this link
What you get in the cmd is probably warning ? I think this might be something to with the resouce configuration in web.xml. Please see Running servlet shows error. Hope it helps.