SpringBoot cannot find handler method to register mongdb requests - mongodb

I have a spring boot app which is trying to connect to Mongo DB, however none of my requests seem to get mapped.
My console log looks like this.
2020-03-03 16:48:57.866 INFO 2100 --- [ main] com.ebay.queens.demo.SpringBootMain : Starting SpringBootMain on DESKTOP-BJ4TA7J with PID 2100 (started by user in C:\Users\user\Documents\Beng Software Engineering\CSC3032-Software Engineering Project\backend)
2020-03-03 16:48:57.872 INFO 2100 --- [ main] com.ebay.queens.demo.SpringBootMain : No active profile set, falling back to default profiles: default
2020-03-03 16:48:59.428 INFO 2100 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-03-03 16:48:59.488 INFO 2100 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 49ms. Found 0 repository interfaces.
2020-03-03 16:49:02.977 INFO 2100 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2020-03-03 16:49:03.094 INFO 2100 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-03 16:49:03.095 INFO 2100 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.26]
2020-03-03 16:49:03.468 INFO 2100 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-03 16:49:03.468 INFO 2100 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5447 ms
2020-03-03 16:49:03.494 INFO 2100 --- [ main] com.ebay.queens.demo.TokenUtilityClass : Token Utility Class
PRD-38907625e4e8-b6b8-4c83-b069-68ac
2020-03-03 16:49:03.577 INFO 2100 --- [ Timer] com.ebay.queens.demo.TokenUtilityClass : Authentication Token
2020-03-03 16:49:04.369 INFO 2100 --- [ main] com.ebay.queens.demo.Login : Login
2020-03-03 16:49:04.371 INFO 2100 --- [ main] com.ebay.queens.demo.SignUp : SignUp
2020-03-03 16:49:05.453 INFO 2100 --- [ Timer] com.ebay.queens.demo.TokenUtilityClass : A21AAEEVZG6qL6IdhIDPRgFdjGFi00knDwdZsJUdkPsKV9g9sI8Q7R0tv4PKtwV53KkUlagV6QsDI5T53RPb4bhJwUkIwb8Cg
2020-03-03 16:49:05.613 INFO 2100 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2020-03-03 16:49:05.613 INFO 2100 --- [ main] org.mongodb.driver.cluster : Adding discovered server localhost:27017 to client view of cluster
2020-03-03 16:49:05.754 INFO 2100 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:17}] to localhost:27017
2020-03-03 16:49:05.762 INFO 2100 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 3]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=5458000}
2020-03-03 16:49:05.764 INFO 2100 --- [localhost:27017] org.mongodb.driver.cluster : Discovered cluster type of STANDALONE
2020-03-03 16:49:05.844 WARN 2100 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2020-03-03 16:49:05.845 WARN 2100 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2020-03-03 16:49:06.059 WARN 2100 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2020-03-03 16:49:06.059 WARN 2100 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
2020-03-03 16:49:06.642 INFO 2100 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9000 (http) with context path ''
2020-03-03 16:49:06.646 INFO 2100 --- [ main] com.ebay.queens.demo.SpringBootMain : Started SpringBootMain in 9.677 seconds (JVM running for 10.521)
2020-03-03 16:49:06.648 INFO 2100 --- [ main] com.ebay.queens.demo.TokenUtilityClass : Token Utility Class
2020-03-03 16:49:06.648 INFO 2100 --- [ main] com.ebay.queens.demo.Paypal : Paypal Class
2020-03-03 16:49:06.653 INFO 2100 --- [ main] com.ebay.queens.demo.Version1Api : Version 1 API
and and my controller class looks like this
package com.ebay.queens.demo.resource;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ebay.queens.demo.User;
import com.ebay.queens.repository.UserRepository;
#RestController
public class UserController {
#Autowired
private UserRepository userRepository;
#PostMapping("/AddUser")
public String saveUser(#RequestBody User user) {
userRepository.save(user);
return "Added user with id: " + user.getId();
}
#GetMapping("/all")
public List<User> getAll(){
List<User> users = this.userRepository.findAll();
return users;
}
}
I have tried reshuffling the packages around but not getting any luck.
Would anyone have any suggestions?

Related

SpringBoot Application Context error: : Kotlin, Gradle,Database, Docker Postgresql

I wanted to setup a connection between my postgresql database, which is inside a docker container and my Project.
The Docker an everything is set up via a docker compose file which looks like this:
version: '3.8'
services:
db:
container_name: postgres_container
image: postgres
restart: always
environment:
POSTGRES_DB: postgres_db
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
PGDATA: /var/lib/postgresql/data
ports:
- "5432:5432"
volumes:
- db-data:/var/lib/postgresql/data
pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4:5.5
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin#admin.com
PGADMIN_DEFAULT_PASSWORD: secret
PGADMIN_LISTEN_PORT: 80
ports:
- "8080:80"
volumes:
- pgadmin-data:/var/lib/pgadmin
links:
- "db:pgsql-server"
volumes:
db-data:
pgadmin-data:
My Project is supposed to be written in Kotlin an I have set up Spring Boot with the initializer, which looked like following:
enter image description here
I have added the following into the application properties file to get a connection to the database.
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres_db
spring.datasource.username=admin
spring.datasource.password=secret
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
This is my main file:
package com.nosiaj.nstudycloud
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
#SpringBootApplication
class NstudycloudApplication
fun main(args: Array<String>) {
runApplication<NstudycloudApplication>(*args)
}
And I wanted to create a table via code
package com.nosiaj.nstudycloud.entity
import javax.persistence.Entity
import javax.persistence.Id
import javax.persistence.Table
#Table(name="customer")
#Entity
class Customer {
#Id
private var uId: String = TODO("initialize me")
private val firstName: String
private val lastName: String
private val email: String
private val phone: String
private val IBAN: String
}
This is my build.gradle.kts file:
plugins {
id("org.springframework.boot") version "2.7.2"
id("io.spring.dependency-management") version "1.0.12.RELEASE"
kotlin("jvm") version "1.6.21"
kotlin("plugin.spring") version "1.6.21"
kotlin("plugin.jpa") version "1.6.21"
}
group = "com.nosiaj"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
runtimeOnly("org.postgresql:postgresql")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
Now when I start the application it connects to the database and creates the table, but I still get Error and the server stops. This is the Output:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.2)
2022-08-07 16:54:22.736 INFO 55209 --- [ main] c.n.n.NstudycloudApplicationKt : Starting NstudycloudApplicationKt using Java 17.0.4 on simba-desktop with PID 55209 (/home/simba/Dokumente/Project/nstudycloud/nstudycloud/build/classes/kotlin/main started by simba in /home/simba/Dokumente/Project/nstudycloud/nstudycloud)
2022-08-07 16:54:22.739 INFO 55209 --- [ main] c.n.n.NstudycloudApplicationKt : No active profile set, falling back to 1 default profile: "default"
2022-08-07 16:54:23.342 INFO 55209 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-08-07 16:54:23.359 INFO 55209 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 3 ms. Found 0 JPA repository interfaces.
2022-08-07 16:54:23.743 INFO 55209 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-08-07 16:54:23.750 INFO 55209 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-08-07 16:54:23.751 INFO 55209 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-08-07 16:54:23.812 INFO 55209 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-08-07 16:54:23.812 INFO 55209 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1026 ms
2022-08-07 16:54:23.949 INFO 55209 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-08-07 16:54:23.991 INFO 55209 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
2022-08-07 16:54:24.110 INFO 55209 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-08-07 16:54:24.182 INFO 55209 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-08-07 16:54:24.286 INFO 55209 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-08-07 16:54:24.298 INFO 55209 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-08-07 16:54:24.594 INFO 55209 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-08-07 16:54:24.602 INFO 55209 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-08-07 16:54:24.635 WARN 55209 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-08-07 16:54:24.928 WARN 55209 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2022-08-07 16:54:24.930 INFO 55209 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-08-07 16:54:24.932 INFO 55209 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-08-07 16:54:24.938 INFO 55209 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2022-08-07 16:54:24.943 INFO 55209 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-08-07 16:54:24.955 INFO 55209 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-08-07 16:54:24.975 ERROR 55209 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.22.jar:5.3.22]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.2.jar:2.7.2]
at com.nosiaj.nstudycloud.NstudycloudApplicationKt.main(NstudycloudApplication.kt:13) ~[main/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.22.jar:5.3.22]
... 14 common frames omitted
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:238) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.7.2.jar:2.7.2]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.7.2.jar:2.7.2]
... 16 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1077) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:234) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
... 18 common frames omitted
Caused by: java.net.BindException: Die Adresse wird bereits verwendet
at java.base/sun.nio.ch.Net.bind0(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.bind(Net.java:555) ~[na:na]
at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337) ~[na:na]
at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294) ~[na:na]
at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:275) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:230) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1227) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1313) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:614) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1074) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
... 20 common frames omitted
Process finished with exit code 1
So why does this Error appear? And how can I solve it ? I don't know what I am doing wrong, if someone could help me, that would be really great !!
Thanks a lot !!
It means another process is running on same port, so you have to kill it.
First, list which app using which that port and get it's pid
lsof -i:8080
Then kill it with
kill <pid>

Spring Cloud config client not picking values from Config server

My Config client is not picking the property values from config
server.
http://localhost:8888/customer_service/default
Above Config server endpoint is returning proper values for Config client,
{
"name": "customer_service",
"profiles": [
"default"
],
"label": null,
"version": "c7648db5662dc65aeaad9c91abbf58b41010be7c",
"state": null,
"propertySources": [
{
"name": "https://github.com/prasadrpm/MicroService_config.git/customer_service.properties",
"source": {
"customer.config.location": "XXXX",
"customer.config.name": "YYYY"
}
}
]
}
Config client bootstrap.properties
server.port=8080
spring.application.name=customer_service
spring.cloud.config.enabled=true
spring.cloud.config.name=config_server
spring.cloud.config.uri=http://localhost:8888
Config client Log
2020-04-10 16:47:00.725 INFO 14976 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-04-10 16:47:03.267 INFO 14976 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config_server, profiles=[default], label=null, version=c7648db5662dc65aeaad9c91abbf58b41010be7c, state=null
2020-04-10 16:47:03.269 INFO 14976 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}]
2020-04-10 16:47:03.280 INFO 14976 --- [ main] com.customer.CustomerServiceApplication : No active profile set, falling back to default profiles: default
...
2020-04-10 16:47:05.164 INFO 14976 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1860 ms
2020-04-10 16:47:05.549 WARN 14976 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'customer.config.location' in value "${customer.config.location}"
2020-04-10 16:47:05.552 INFO 14976 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-04-10 16:47:05.577 INFO 14976 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-10 16:47:05.595 ERROR 14976 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'customer.config.location' in value "${customer.config.location}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
The URL that returns you correct properties/configuration is: localhost:8888/customer_service/default
Client application is querying for properties based on following data:
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config_server, profiles=[default], label=null, version=c7648db5662dc65aeaad9c91abbf58b41010be7c, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}]
com.customer.CustomerServiceApplication : No active profile set, falling back to default profiles: default
...
So, effectively, client application is calling:
localhost:8888/config_server/default
So, there are two solutions:
delete spring.cloud.config.name=config_server property in bootstrap.properties, and your application should be able to fetch properties.
update value of spring.cloud.config.name to customer_service service. But if you do not provide spring.cloud.config.name explicitly, then client will use spring.application.name as the default value for spring.cloud.config.name.
What annotation you had used here?
It can be easily retrieved like this.
#Value("${customer.config.location}")
private String someOtherProperty;
and it is not needed
spring.cloud.config.name=config_server

Failed steps are not recorded in DB

I'm simulating the error handling behavior of composed task, the failedTask composed task definition looks like this :
<f1: sampleTask --fail=true --custom-argument=someMessage || f2: sampleTask>
The sampleTask class runner :
public class SampleTask implements ApplicationRunner {
#Autowired
SampleTaskProperties taskProperties;
#Override
public void run(ApplicationArguments p) throws Exception {
if(taskProperties.isFail()){
throw new Exception(taskProperties.getCustomArgument());
}
}
}
dependencies :
ext {
springCloudTaskVersion = '1.2.2.RELEASE'
springCloudVersion = 'Edgware.RC1'
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-task')
compile('org.springframework.cloud:spring-cloud-stream-binder-rabbit')
compile('org.springframework.cloud:spring-cloud-task-stream')
compile 'org.postgresql:postgresql:42.1.4'
runtime 'org.springframework.boot:spring-boot-starter-jdbc'
compile 'org.springframework.boot:spring-boot-starter'
compileOnly("org.springframework.boot:spring-boot-configuration-processor");
testCompile('org.springframework.boot:spring-boot-starter-test')
}
The problem is that the end time of f1 is not recorder in DB and failedTask status is shown as STARTED in dashboard UI, end_time of failedTask and failedTask-f1 are both empty in task_executions table.
Below are the logs of the f1 execution :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-11-20 12:09:06.869 WARN 28244 --- [ main] o.s.boot.SpringApplication : Error handling failed (failed to convert object to Message; nested exception is org.springframework.messaging.MessagingException: At most one parameter (or expression via method-level #Payload) may be mapped to the payload or Message. Found more than one on method [public abstract void org.springframework.cloud.task.listener.TaskExecutionListener.onTaskFailed(org.springframework.cloud.task.repository.TaskExecution,java.lang.Throwable)])
2017-11-20 12:09:06.895 ERROR 28244 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:726) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:713) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:703) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:304) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at com.philips.asp.flow.task.SampleTaskApplication.main(SampleTaskApplication.java:31) [classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [sample-task-0.1.11-SNAPSHOT.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [sample-task-0.1.11-SNAPSHOT.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [sample-task-0.1.11-SNAPSHOT.jar:na]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [sample-task-0.1.11-SNAPSHOT.jar:na]
Caused by: java.lang.Exception: sdfsdf
at com.philips.asp.flow.task.SampleTaskConfiguration$SampleTask.run(SampleTaskConfiguration.java:53) ~[classes!/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:723) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
... 14 common frames omitted
2017-11-20 12:09:06.898 INFO 28244 --- [ main] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#2d363fb3: startup date [Mon Nov 20 12:08:54 IST 2017]; root of context hierarchy
2017-11-20 12:09:06.899 INFO 28244 --- [ main] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#6a55299e: startup date [Mon Nov 20 12:09:05 IST 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#2d363fb3
2017-11-20 12:09:06.915 INFO 28244 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147483647
2017-11-20 12:09:06.916 INFO 28244 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147482647
2017-11-20 12:09:06.917 INFO 28244 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2017-11-20 12:09:06.917 INFO 28244 --- [ main] ProxyFactoryBean$MethodInvocationGateway : stopped taskEventListener
2017-11-20 12:09:06.917 INFO 28244 --- [ main] ProxyFactoryBean$MethodInvocationGateway : stopped taskEventListener
2017-11-20 12:09:06.917 INFO 28244 --- [ main] ProxyFactoryBean$MethodInvocationGateway : stopped taskEventListener
2017-11-20 12:09:06.917 INFO 28244 --- [ main] o.s.i.gateway.GatewayProxyFactoryBean : stopped taskEventListener
2017-11-20 12:09:06.918 INFO 28244 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2017-11-20 12:09:06.918 INFO 28244 --- [ main] o.s.i.channel.PublishSubscribeChannel : Channel 'sampleTask:12890.errorChannel' has 0 subscriber(s).
2017-11-20 12:09:06.918 INFO 28244 --- [ main] o.s.i.endpoint.EventDrivenConsumer : stopped _org.springframework.integration.errorLogger
2017-11-20 12:09:06.918 INFO 28244 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase -2147482648
2017-11-20 12:09:06.919 INFO 28244 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2017-11-20 12:09:06.919 INFO 28244 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Unregistering JMX-exposed beans
2017-11-20 12:09:06.919 INFO 28244 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: task-events
2017-11-20 12:09:06.919 INFO 28244 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: errorChannel
2017-11-20 12:09:06.919 INFO 28244 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: nullChannel
2017-11-20 12:09:06.919 INFO 28244 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: _org.springframework.integration.errorLogger.handler
2017-11-20 12:09:06.919 INFO 28244 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2017-11-20 12:09:06.919 INFO 28244 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2017-11-20 12:09:06.920 WARN 28244 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'taskLifecycleListener': org.springframework.messaging.converter.MessageConversionException: failed to convert object to Message; nested exception is org.springframework.messaging.MessagingException: At most one parameter (or expression via method-level #Payload) may be mapped to the payload or Message. Found more than one on method [public abstract void org.springframework.cloud.task.listener.TaskExecutionListener.onTaskFailed(org.springframework.cloud.task.repository.TaskExecution,java.lang.Throwable)]
2017-11-20 12:09:06.920 INFO 28244 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler'
If I remove the
compile('org.springframework.cloud:spring-cloud-stream-binder-rabbit)`
compile('org.springframework.cloud:spring-cloud-task-stream')
dependencies - the below warning log message disappears and everything works as expected.
2017-11-20 12:09:06.920 WARN 28244 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'taskLifecycleListener': org.springframework.messaging.converter.MessageConversionException: failed to convert object to Message; nested exception is org.springframework.messaging.MessagingException: At most one parameter (or expression via method-level #Payload) may be mapped to the payload or Message. Found more than one on method [public abstract void org.springframework.cloud.task.listener.TaskExecutionListener.onTaskFailed(org.springframework.cloud.task.repository.TaskExecution,java.lang.Throwable)]
Please advice.
Furer,
Thanks for detailed explanation of the issue. After researching the issue you have discussed in the issue above, it has been identified as the same issue issue as https://github.com/spring-cloud/spring-cloud-task/issues/341. And has been addressed in this PR: https://github.com/spring-cloud/spring-cloud-task/pull/344

Spring JPA cannot connect to Postgresql

I am trying to write a Spring Data JPA application with Postgres.
I am getting an error: FATAL: password authentication failed for user
I tried the same thing writing the connection using regular JDBC, and all worked fine, same username/password/database/hostname.
The property file I'm using for Spring Data JPA contains the following:
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
spring.datasource.username=test_java
spring.datasource.password=easy_password
server.port=8080
As compared to the property file I'm using for the java jdbc test:
db.url=jdbc:postgresql://localhost:5432/testdb
db.user=test_java
db.passwd=easy_password
The Java code looks like this:
public void testSelectWithPropertyFile() {
Logger lgr = Logger.getLogger(getClass().getName());
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
Properties props = new Properties();
FileInputStream in = null;
try {
in = new FileInputStream("target/classes/properties/database.properties");
props.load(in);
} catch (IOException ex) {
lgr.log(Level.SEVERE, ex.getMessage(), ex);
return;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
lgr.log(Level.SEVERE, ex.getMessage(), ex);
}
}
String url = props.getProperty("db.url");
String user = props.getProperty("db.user");
String passwd = props.getProperty("db.passwd");
try {
con = DriverManager.getConnection(url, user, passwd);
pst = con.prepareStatement("SELECT * FROM Authors");
rs = pst.executeQuery();
while (rs.next()) {
System.out.print(rs.getInt(1));
System.out.print(": ");
System.out.println(rs.getString(2));
}
} catch (Exception ex) {
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pst != null) {
pst.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
Here's the error log I get in Spring Boot JPA:
2016-10-14 11:09:21.593 INFO 6948 --- [ main] com.example.JpaPostgresApplication : Starting JpaPostgresApplication on DESKTOP-53J32BH with PID 6948 (C:\Users\charb\workspace\JPA_POSTGRES\target\classes started by charb in C:\Users\charb\workspace\JPA_POSTGRES)
2016-10-14 11:09:21.595 INFO 6948 --- [ main] com.example.JpaPostgresApplication : No active profile set, falling back to default profiles: default
2016-10-14 11:09:21.679 INFO 6948 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#72f926e6: startup date [Fri Oct 14 11:09:21 BST 2016]; root of context hierarchy
2016-10-14 11:09:23.402 INFO 6948 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$72d9bd3b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-10-14 11:09:23.922 INFO 6948 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-10-14 11:09:23.933 INFO 6948 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-10-14 11:09:23.934 INFO 6948 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.5
2016-10-14 11:09:24.062 INFO 6948 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-10-14 11:09:24.062 INFO 6948 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2387 ms
2016-10-14 11:09:24.230 INFO 6948 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-10-14 11:09:24.234 INFO 6948 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-10-14 11:09:24.235 INFO 6948 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-10-14 11:09:24.235 INFO 6948 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-10-14 11:09:24.235 INFO 6948 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-10-14 11:09:24.478 INFO 6948 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-10-14 11:09:24.492 INFO 6948 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-10-14 11:09:24.554 INFO 6948 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.11.Final}
2016-10-14 11:09:24.555 INFO 6948 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-10-14 11:09:24.557 INFO 6948 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-10-14 11:09:24.602 INFO 6948 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2016-10-14 11:09:24.828 ERROR 6948 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "test_java "
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:446) ~[postgresql-9.4.1211.jre7.jar:9.4.1211.jre7]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:220) ~[postgresql-9.4.1211.jre7.jar:9.4.1211.jre7]
I can't understand how come Spring Data JPA can't authenticate while normal java JDBC is working ok.
Replace spring.database.driverClassName=org.postgresql.Driver with
spring.datasource.driverClassName=org.postgresql.Driver
Your problem is authentication,
Se message
password authentication failed for user "test_java "
Are sure correct this information connection? because that is your problem
if is correct then make a test, connect same other client in your base, with local.
If ok. the problem it's not ability connection remote.
For ability connect remote access pg_hba.config then ability remote connect (or other file that configuration, your database)
See: that part of my file configuration:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.2.0/24 md5
the permit connection local and network 192.168.2.0, has many way configure that

Spring Batch - the batch works in Eclipse but not as a JAR - without explicit DEBUG log

I am new to Spring. My batch works in Eclipse using Spring Boot.
public class Main {
public static void main(String [] args) {
System.exit(SpringApplication.exit(SpringApplication.run(BatchConfiguration.class, args)));
}
}
Here are the Eclipse's logs.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.1.4.RELEASE)
2014-08-08 12:01:09.714 INFO 292 --- [ main] f.i.a.fczeuj.springbatch.Main : Starting Main on W100023928 with PID 292 (started by Me in D:\Eclipse_workspace\SpringBatchJavaConfig)
2014-08-08 12:01:09.776 INFO 292 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#714ae2c1: startup date [Fri Aug 08 12:01:09 CEST 2014]; root of context hierarchy
2014-08-08 12:01:10.494 INFO 292 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'org.springframework.boot.autoconfigure.AutoConfigurationPackages': replacing [Generic bean: class [org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
2014-08-08 12:01:10.979 WARN 292 --- [ main] o.s.c.a.ConfigurationClassEnhancer : #Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as #Autowired, #Resource and #PostConstruct within the method's declaring #Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see #Bean Javadoc for complete details
2014-08-08 12:01:10.994 WARN 292 --- [ main] o.s.c.a.ConfigurationClassEnhancer : #Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as #Autowired, #Resource and #PostConstruct within the method's declaring #Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see #Bean Javadoc for complete details
2014-08-08 12:01:11.166 INFO 292 --- [ main] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: org.postgresql.Driver
sql=insert into schema_batch_01.table_batch_donnees_massives values (:num_ligne,(((extract('epoch' from statement_timestamp())*1000)::bigint)-1407492071384)/1000,:prenom, :nom, :rue, :ville, :etat)
2014-08-08 12:01:11.618 INFO 292 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [org/springframework/batch/core/schema-postgresql.sql]
2014-08-08 12:01:11.619 INFO 292 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [org/springframework/batch/core/schema-postgresql.sql] in 1 ms.
2014-08-08 12:01:11.822 INFO 292 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2014-08-08 12:01:11.838 INFO 292 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: []
2014-08-08 12:01:11.884 INFO 292 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: POSTGRES
2014-08-08 12:01:12.025 INFO 292 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2014-08-08 12:01:12.493 INFO 292 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] launched with the following parameters: [{run.id=28}]
2014-08-08 12:01:12.664 INFO 292 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [taskletTruncate]
truncateDonnees DataSource=
org.springframework.jdbc.datasource.DriverManagerDataSource#7e913c56
Username=
role_cnx_batch_seminaire_dev
2014-08-08 12:01:13.102 INFO 292 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [stepInserts]
2014-08-08 12:01:18.079 INFO 292 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] completed with the following parameters: [{run.id=28}] and the following status: [COMPLETED]
2014-08-08 12:01:18.079 INFO 292 --- [ main] f.i.a.fczeuj.springbatch.Main : Started Main in 8.677 seconds (JVM running for 9.239)
2014-08-08 12:01:18.079 INFO 292 --- [ main] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#714ae2c1: startup date [Fri Aug 08 12:01:09 CEST 2014]; root of context hierarchy
2014-08-08 12:01:18.079 INFO 292 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
So I have built a JAR with maven dependencies and main class in the MANIFEST and run the JAR
java -jar myArchive.jar
But the JAR does nothing, without ERRORS in the DOS logs.
2014-08-08 12:10:47.125 DEBUG --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'batchConfiguration'
sql=insert into schema_batch_01.table_batch_donnees_massives values (:num_ligne,(((extract('epoch' from statement_timestamp())*1000)::bigint)-1407492647125)/1000,:prenom, :nom
, :rue, :ville, :etat)
2014-08-08 12:10:47.141 DEBUG --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Eagerly caching bean 'writer' to allow for resolving potential circular refere
nces
2014-08-08 12:10:47.141 DEBUG --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Invoking afterPropertiesSet() on bean with name 'writer'
2014-08-08 12:10:47.141 DEBUG --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'writer'
2014-08-08 12:10:47.141 DEBUG --- [ main] s.c.a.AnnotationConfigApplicationContext : Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using defa
ult [org.springframework.context.support.DefaultLifecycleProcessor#4dc1c92b]
2014-08-08 12:10:47.141 DEBUG --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'lifecycleProcessor'
2014-08-08 12:10:47.141 DEBUG --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
2014-08-08 12:10:47.141 DEBUG --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
2014-08-08 12:10:47.141 DEBUG --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.liveBeansView.mbeanDomain' in [class path resource [
spring.batch.context.properties]]
2014-08-08 12:10:47.141 DEBUG --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.liveBeansView.mbeanDomain' in any property source.
Returning [null]
2014-08-08 12:10:47.157 INFO --- [ main] f.i.a.fczeuj.springbatch.Main : Started Main in 0.952 seconds (JVM running for 1.264)
2014-08-08 12:10:47.157 INFO --- [ main] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationCont
ext#356f144c: startup date [Fri Aug 08 12:10:46 CEST 2014]; root of context hierarchy
2014-08-08 12:10:47.157 DEBUG --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'lifecycleProcessor'
2014-08-08 12:10:47.157 DEBUG --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Destroying singletons in org.springframework.beans.factory.support.DefaultList
ableBeanFactory#11e7c5cb: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowi
redAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,batc
hConfiguration,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcess
or.enhancedConfigurationProcessor,org.springframework.batch.core.configuration.annotation.ScopeConfiguration,stepScope,jobScope,org.springframework.batch.core.configuration.an
notation.SimpleBatchConfiguration,jobRepository,jobLauncher,jobRegistry,jobExplorer,transactionManager,jobBuilders,stepBuilders,fr.insee.architecture.fczeuj.springbatch.Contex
tWithProperties,dataSource,nbIteration,org.springframework.boot.autoconfigure.AutoConfigurationPackages,taskletTruncate,reader,processor,writer,job,stepInserts]; root of facto
ry hierarchy
2014-08-08 12:10:47.157 DEBUG --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invoking destroy() on bean with name 'batchConfiguration'
2014-08-08 12:10:47.157 DEBUG --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invoking destroy() on bean with name 'org.springframework.batch.core.configura
tion.annotation.SimpleBatchConfiguration'
2014-08-08 12:10:47.157 DEBUG --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invoking destroy() on bean with name 'fr.architecture.springbatch
.ContextWithProperties'
2014-08-08 12:10:47.157 DEBUG --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invoking destroy() on bean with name 'org.springframework.batch.core.configura
tion.annotation.ScopeConfiguration'
the missing logs between the JAR and Eclipse is just after the log line :
sql=insert into schema_batch_01.table_batch_donnees_massives values (:num_ligne,(((extract('epoch' from statement_timestamp())*1000)::bigint)-1407492647125)/1000,:prenom, :nom
, :rue, :ville, :etat)
Do you have an idea why my JAR aborts without running the Job ? Thank you.
Are you building with maven? If so, using the maven-assembly-plugin does not result in a jar file that runs the batch job, you'll need to use the spring-boot-maven-plugin like this:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.1.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>your.MainClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
You can then use the standard "mvn clean package" command to get an executable jar that contains all necessary dependencies and the correct manifest file.