Error: Field required a bean of type that could not be found. Consider defining a bean - spring

While creating a spring boot application on Spring boot 1.5.9, I am getting below error message. Can any body please help? Thanks in advance.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.9.RELEASE)
2018-01-26 22:16:01.534 INFO 7176 --- [ main] com.myapp.MyAppApplication : Starting MyAppApplication on DESKTOP-29H8ALN with PID 7176 (F:\My_SpringBoot_WorkSpace_20_01_2018\MyApp\MyApp\target\classes started by Tanmoy in F:\My_SpringBoot_WorkSpace_20_01_2018\MyApp\MyApp)
2018-01-26 22:16:01.534 INFO 7176 --- [ main] com.myapp.MyAppApplication : No active profile set, falling back to default profiles: default
2018-01-26 22:16:01.590 INFO 7176 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#61009542: startup date [Fri Jan 26 22:16:01 IST 2018]; root of context hierarchy
2018-01-26 22:16:02.889 INFO 7176 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 9001 (http)
2018-01-26 22:16:02.903 INFO 7176 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-01-26 22:16:02.904 INFO 7176 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
2018-01-26 22:16:03.075 INFO 7176 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-01-26 22:16:03.075 INFO 7176 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1490 ms
2018-01-26 22:16:03.238 INFO 7176 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-01-26 22:16:03.242 INFO 7176 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-26 22:16:03.243 INFO 7176 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-01-26 22:16:03.243 INFO 7176 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-01-26 22:16:03.243 INFO 7176 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-01-26 22:16:03.277 WARN 7176 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'customerService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerService': Unsatisfied dependency expressed through field 'customersRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.myapp.repository.CustomersRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
2018-01-26 22:16:03.278 INFO 7176 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-01-26 22:16:03.311 INFO 7176 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-26 22:16:03.396 ERROR 7176 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field customersRepository in com.myapp.service.CustomerService required a bean of type 'com.myapp.repository.CustomersRepository' that could not be found.
Action:
Consider defining a bean of type 'com.myapp.repository.CustomersRepository' in your configuration.
I am using this settings:
Spring Boot 1.5.9
Oracle 11g database.
Please find the below classes I am using along with the pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tanmoy</groupId>
<artifactId>MyApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyApp</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.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-web</artifactId>
</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>
<exclusions>
<exclusion>
<artifactId>hibernate-entitymanager</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>12.1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Java code - application:
package com.myapp;
import javax.transaction.Transactional;
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.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.myapp.entity.Customers;
import com.myapp.repository.CustomersRepository;
import com.myapp.service.CustomerService;
#SpringBootApplication
public class MyAppApplication {
public static void main(String[] args) {
SpringApplication.run(MyAppApplication.class, args);
}
#Bean
public CommandLineRunner demo(CustomersRepository repository) {
return (args) -> {
// fetch all customers
for (Customers customer : repository.findAll()) {
}
};
}
}
Java code - repository:
package com.myapp.repository;
import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import com.myapp.entity.Customers;
#Repository
public interface CustomersRepository extends CrudRepository<Customers, Integer> {
#Query("select * from customers")
public List<Customers> getAllCustomerts();
}
Java code - service:
package com.myapp.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.myapp.repository.CustomersRepository;
#Service
public class CustomerService {
#Autowired
CustomersRepository customersRepository;
public void getAllCustomers() {
System.out.println(customersRepository.findAll());
}
}

Remove the #Repository annotation from CustomersRepository.
The interface CrudRepository is already registered in Spring's container and it can be injected already (also its child interfaces).

I think there is more in the exception stacktrace which was not shared, I think exception will point to incorrect query. The query in CustomersRespository should be like below:
#Query("select c from Customers c")
public List<Customers> getAllCustomerts();

Why are you defining a getAllCustomers in the repository if you never use it?
The CrudRepository already gives you for free some useful method implementations without you having to write a single line of code besides the interface declaration.
My suggestion is to remove the getAllCustumers in repository and call findAll on the repository from the service.

#Autowired
CustomersRepository customersRepository;
This is not the proper way to Autowire. This is:
CustomersRepository customersRepository;
#Autowire
public defaultConstructor(CustomerRepository customerRepository){
this.customerRepository = customerRepository;
}
note: defaultConstructor is simply your class name (default constructor).

Related

ShedLock with Spring boot with couchbase

Given my Spring boot application code:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.couchbase.client.java.Bucket;
import net.javacrumbs.shedlock.provider.couchbase.javaclient3.CouchbaseLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
#SpringBootApplication
#EnableScheduling
#EnableSchedulerLock(defaultLockAtMostFor = "10m")
public class MythoughtsApplication {
public static void main(String[] args) {
SpringApplication.run(MythoughtsApplication.class, args);
}
#Bean
public CouchbaseLockProvider lockProvider(Bucket bucket) {
return new CouchbaseLockProvider(bucket);
}
}
pom.xml
using the latest shedlock in the below pom.xml file.
<?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.7.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.guru</groupId>
<artifactId>mythoughts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mythoughts</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-couchbase</artifactId>
</dependency>
<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>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
</dependency>
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>core-io</artifactId>
<version>2.3.1</version>
</dependency>
**<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
**<version>4.37.0</version>**
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-couchbase-javaclient3</artifactId>
**<version>4.37.0</version>**
</dependency>**
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
couchbase Connection file
#Configuration
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
#Override
public String getConnectionString() {
// TODO Auto-generated method stub
return "127.0.0.1";
}
#Override
public String getUserName() {
// TODO Auto-generated method stub
return "admin";
}
#Override
public String getPassword() {
// TODO Auto-generated method stub
return "1234";
}
#Override
public String getBucketName() {
// TODO Auto-generated method stub
return "admin";
}
}
controller file
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.guru.mythoughts.service.UserService;
import net.javacrumbs.shedlock.core.LockAssert;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
#RestController
public class UserController {
#Scheduled(cron = "*/5 * * * * *")
#SchedulerLock(name = "scheduledTaskName", lockAtMostFor = "PT5M", lockAtLeastFor = "PT4M")
public void scheduledTask() {
LockAssert.assertLocked();
System.out.println("cloked");
}
}
Output with error:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.0)
2022-06-21 17:36:01.346 INFO 21152 --- [ main] c.zzz.mythoughts.MyApplication : Starting MythoughtsApplication using Java 1.8.0_271 on DESKTOP-O8IM34ASBST with PID 21152 (C:\Users\G\Downloads\mythoughts\target\classes started by in C:\Users\G\Downloads\mythoughts)
2022-06-21 17:36:01.350 INFO 21152 --- [ main] c.zzz.mythoughts.MythoughtsApplication : No active profile set, falling back to 1 default profile: "default"
2022-06-21 17:36:01.889 INFO 21152 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Couchbase repositories in DEFAULT mode.
2022-06-21 17:36:02.033 INFO 21152 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 139 ms. Found 0 Couchbase repository interfaces.
2022-06-21 17:36:02.039 INFO 21152 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Couchbase repositories in DEFAULT mode.
2022-06-21 17:36:02.061 INFO 21152 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 22 ms. Found 1 Couchbase repository interfaces.
2022-06-21 17:36:02.504 INFO 21152 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-06-21 17:36:02.514 INFO 21152 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-06-21 17:36:02.514 INFO 21152 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.63]
2022-06-21 17:36:02.751 INFO 21152 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-06-21 17:36:02.751 INFO 21152 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1346 ms
2022-06-21 17:36:03.445 INFO 21152 --- [ cb-events] com.couchbase.core : [com.couchbase.core][CoreCreatedEvent] {"clientVersion":"3.3.0","clientGitHash":"${buildNumber}","coreVersion":"2.3.1","coreGitHash":"${buildNumber}","userAgent":"couchbase-java/3.3.0 (Windows 10 10.0 amd64; Java HotSpot(TM) 64-Bit Server VM 1.8.0_271-b09)","maxNumRequestsInRetry":32768,"ioEnvironment":{"nativeIoEnabled":true,"eventLoopThreadCount":4,"eventLoopGroups":["NioEventLoopGroup"]},"ioConfig":{"captureTraffic":[],"mutationTokensEnabled":true,"networkResolution":"auto","dnsSrvEnabled":true,"tcpKeepAlivesEnabled":true,"tcpKeepAliveTimeMs":60000,"configPollIntervalMs":2500,"kvCircuitBreakerConfig":"disabled","queryCircuitBreakerConfig":"disabled","viewCircuitBreakerConfig":"disabled","searchCircuitBreakerConfig":"disabled","analyticsCircuitBreakerConfig":"disabled","managerCircuitBreakerConfig":"disabled","eventingCircuitBreakerConfig":"disabled","backupCircuitBreakerConfig":"disabled","numKvConnections":1,"maxHttpConnections":12,"idleHttpConnectionTimeoutMs":4500,"configIdleRedialTimeoutMs":300000,"memcachedHashingStrategy":"StandardMemcachedHashingStrategy"},"compressionConfig":{"enabled":true,"minRatio":0.83,"minSize":32},"securityConfig":{"tlsEnabled":false,"nativeTlsEnabled":true,"hostnameVerificationEnabled":true,"trustCertificates":null,"trustManagerFactory":null,"ciphers":[]},"timeoutConfig":{"kvMs":2500,"kvDurableMs":10000,"managementMs":75000,"queryMs":75000,"viewMs":75000,"searchMs":75000,"analyticsMs":75000,"connectMs":10000,"disconnectMs":10000,"eventingMs":75000,"backupMs":75000},"loggerConfig":{"customLogger":null,"fallbackToConsole":false,"consoleLogLevel":{"name":"INFO","resourceBundleName":"sun.util.logging.resources.logging","localizedName":"INFO"},"consoleLoggerFormatter":"DefaultLoggerFormatter","disableSlf4j":false,"loggerName":"CouchbaseLogger","diagnosticContextEnabled":false},"orphanReporterConfig":{"emitIntervalMs":10000,"sampleSize":10,"queueLength":1024,"enabled":true},"thresholdLoggingTracerConfig":{"enabled":true,"emitIntervalMs":10000,"sampleSize":10,"queueLength":1024,"kvThresholdMs":500,"queryThresholdMs":1000,"searchThresholdMs":1000,"analyticsThresholdMs":1000,"viewThresholdMs":1000},"loggingMeterConfig":{"enabled":true,"emitIntervalMs":600000},"retryStrategy":"BestEffortRetryStrategy","requestTracer":"ThresholdLoggingTracer","meter":"LoggingMeter","numRequestCallbacks":0,"scheduler":"ParallelScheduler","schedulerThreadCount":8,"transactionsConfig":{"durabilityLevel":"MAJORITY","timeoutMs":15000,"cleanupConfig":{"runLostAttemptsCleanupThread":true,"runRegularAttemptsCleanupThread":true,"cleanupWindowMs":60000,"cleanupSet":""},"numAtrs":1024,"metadataCollection":"none","scanConsistency":"none"}} {"coreId":"0xa407cf8700000001","seedNodes":[{"address":"127.0.0.1"}]}
2022-06-21 17:36:03.445 INFO 21152 --- [ cb-events] com.couchbase.transactions : [com.couchbase.transactions][TransactionsStartedEvent] Transactions successfully initialised, regular cleanup enabled=true, lost cleanup enabled=true
2022-06-21 17:36:03.452 INFO 21152 --- [ cb-events] com.couchbase.node : [com.couchbase.node][NodeConnectedEvent] Node connected {"coreId":"0xa407cf8700000001","managerPort":"8091","remote":"127.0.0.1"}
2022-06-21 17:36:03.985 WARN 21152 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'lockProvider' defined in com.guru.mythoughts.MythoughtsApplication: Unsatisfied dependency expressed through method 'lockProvider' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.couchbase.client.java.Bucket' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2022-06-21 17:36:04.026 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup : [com.couchbase.transactions.cleanup][LogEvent] Waiting for 1 regular background threads to exit
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] c.c.transactions.cleanup.regular : [com.couchbase.transactions.cleanup.regular][LogEvent] Stopping background cleanup thread for transactions from this client
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup.lost : [com.couchbase.transactions.cleanup.lost][LogEvent] Client d9110 has been told to cancel
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup.lost : [com.couchbase.transactions.cleanup.lost][LogEvent] Client d9110 stopping lost cleanup process, 0 threads running
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup.lost : [com.couchbase.transactions.cleanup.lost][LogEvent] Client d9110 stopped lost cleanup process and removed client from client records
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.transactions.cleanup : [com.couchbase.transactions.cleanup][LogEvent] Background threads have exitted
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.node : [com.couchbase.node][NodeDisconnectedEvent][667us] Node disconnected {"coreId":"0xa407cf8700000001","managerPort":"8091","remote":"127.0.0.1"}
2022-06-21 17:36:04.027 INFO 21152 --- [ cb-events] com.couchbase.core : [com.couchbase.core][ShutdownCompletedEvent][19ms] Completed shutdown and closed all open buckets {"coreId":"0xa407cf8700000001"}
2022-06-21 17:36:04.118 INFO 21152 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-06-21 17:36:04.130 INFO 21152 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-21 17:36:04.157 ERROR 21152 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method lockProvider in com.guru.mythoughts.MythoughtsApplication required a bean of type 'com.couchbase.client.java.Bucket' that could not be found.
Action:
Consider defining a bean of type 'com.couchbase.client.java.Bucket' in your configuration.
I have given sample code and when I tried to run the application I am getting the above error. I have scheduled a method in controller and it should run for every 5 seconds.
I have followed the above in the given below link
https://gitcode.net/mirrors/lukas-krecan/ShedLock/-/tree/master/providers/couchbase
How can i solve this error?
Autowired the Cluster class and used the cluster to get the bucket details with bean creation in main class which return the bucket object. please see the same code and it is working fine.
#Autowired
Cluster cluster;
#Bean
public Bucket getBucket() {
return cluster.bucket("bucket");
}
}
Another option is to have a Cluster argument to your getBucket() bean method.
#Bean
public Bucket getBucket(Cluster cluster){
return cluster.bucket("myBucket");
}

Rest controller not registerring

I am building an app with JWT security but it keeps ignoring my rest controllers, and not registering the APIs:
Here is my pom:
<?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.6.0</version>
<relativePath/>
</parent>
<groupId>org.home</groupId>
<artifactId>testapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testapp</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.6.3</version>
</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>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.25</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!-- SECURITY -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<!-- JWT -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here is my application.yml
...
server:
url: https://localhost:8443
port: 8443
ssl:
enabled: true
key-store: classpath:keystore/my_keystore.p12
key-store-password: mySuperPassword#
key-store-type: pkcs12
key-alias: mykey
Here is my main class :
package org.home.mysecurityapplication;
#SpringBootApplication(scanBasePackages={"org.home.**"})
public class MySecureApplication {
public static void main(String[] args) {
SpringApplication.run(MySecureApplication.class, args);
}
}
Here is my web initializer :
package org.home.mysecurityapplication.configuration;
public class WebInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext sc) {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.setConfigLocations("org.home.**");
rootContext.refresh();
rootContext.setServletContext(sc);
sc.addListener(new ContextLoaderListener(rootContext));
ServletRegistration.Dynamic apiSR = sc.addServlet("api-dispatcher", new DispatcherServlet(rootContext));
apiSR.setLoadOnStartup(1);
apiSR.addMapping("/");
}
}
Here i am evabling mvc :
package org.home.mysecurityapplication.configuration;
#Configuration
#ComponentScan(basePackages={"org.home.**"})
#EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
}
Here is my security configurer adapter:
package org.home.mysecurityapplication.security;
#Configuration
#EnableWebSecurity
#EnableGlobalMethodSecurity(securedEnabled=true, prePostEnabled=true)
public class MyWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
private final MyAuthenticationProvider myAuthenticationProvider;
private final CredentialsFilter credentialsFilter;
#Autowired
public MyWebSecurityConfigurerAdapter(MyAuthenticationProvider myAuthenticationProvider, CredentialsFilter credentialsFilter) {
this.myAuthenticationProvider = myAuthenticationProvider;
this.credentialsFilter = credentialsFilter;
}
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers(HttpMethod.POST, "/roles").permitAll() // everyone should access login-api
;
// disable csrf
http.csrf().disable();
// app session is stateless
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(credentialsFilter, UsernamePasswordAuthenticationFilter.class);
http.requiresChannel(channel -> channel.anyRequest().requiresSecure());
}
#Override
protected void configure(AuthenticationManagerBuilder auth) {
auth.eraseCredentials(false)
.authenticationProvider(myAuthenticationProvider);
}
}
Here is my controller:
package org.home.mysecurityapplication.security.controller;
#RestController
#RequestMapping(value="")
public class SecurityController {
#Autowired
private SecurityService securityServiceImpl;
private static final Logger logger = LoggerFactory.getLogger(SecurityController.class);
#RequestMapping(value = "/roles", method = RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE, produces=MediaType.TEXT_PLAIN_VALUE)
#ResponseStatus(HttpStatus.OK)
public #ResponseBody
String generateToken(#RequestBody CredentialsDTO credentials) throws MyRestPreconditionsException {
logger.debug("User "+credentials.getUsername()+" logging in ...");
String token = securityServiceImpl.generateTokenForUser(credentials);
logger.debug("User "+credentials.getUsername()+" log in successfull.");
return token;
}
}
As you can see, rest controller /roles does not register :(
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.0)
2022-02-15 22:37:37.906 INFO 10720 --- [ main] l.h.myapp.MySecurityApplication : Starting MySecurityApplication using Java 17.0.2 on HAL-9015 with PID 10720 (C:\Users\Lazaruss\IdeaProjects\greenhealth2\target\classes started by Lazaruss in C:\Users\Lazaruss\IdeaProjects\greenhealth2)
2022-02-15 22:37:37.909 INFO 10720 --- [ main] l.h.myapp.MySecurityApplication : No active profile set, falling back to default profiles: default
2022-02-15 22:37:38.629 INFO 10720 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-02-15 22:37:38.712 INFO 10720 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 68 ms. Found 1 JPA repository interfaces.
2022-02-15 22:37:39.879 INFO 10720 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8443 (https)
2022-02-15 22:37:39.894 INFO 10720 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-02-15 22:37:39.894 INFO 10720 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.55]
2022-02-15 22:37:40.036 INFO 10720 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-02-15 22:37:40.036 INFO 10720 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2067 ms
2022-02-15 22:37:40.330 INFO 10720 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-02-15 22:37:40.406 INFO 10720 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.1.Final
2022-02-15 22:37:40.652 INFO 10720 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-02-15 22:37:41.061 INFO 10720 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2022-02-15 22:37:41.840 INFO 10720 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-02-15 22:37:41.851 INFO 10720 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-02-15 22:37:42.435 WARN 10720 --- [ 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-02-15 22:37:42.957 INFO 10720 --- [ main] o.s.s.w.a.c.ChannelProcessingFilter : Validated configuration attributes
2022-02-15 22:37:42.959 INFO 10720 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.access.channel.ChannelProcessingFilter#7af0693b, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#110318a7, org.springframework.security.web.context.SecurityContextPersistenceFilter#265c0752, org.springframework.security.web.header.HeaderWriterFilter#3c9cfcde, org.springframework.security.web.authentication.logout.LogoutFilter#2e5c7cd5, lazaruss.home.myapp.security.CredentialsFilter#6dc2e473, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#7a75183d, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#6f695077, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#42ac309, org.springframework.security.web.session.SessionManagementFilter#799fc4c9, org.springframework.security.web.access.ExceptionTranslationFilter#34fcc5e3, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#152dbf8e]
2022-02-15 22:37:43.681 INFO 10720 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8443 (https) with context path ''
2022-02-15 22:37:43.690 INFO 10720 --- [ main] l.h.myapp.MySecurityApplication : Started MySecurityApplication in 6.437 seconds (JVM running for 7.137)
2022-02-15 22:37:49.009 INFO 10720 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
I suspect you are having a problem with the scanned packages.
#SpringBootApplication encapsulates #Configuration, #EnableAutoConfiguration, and #ComponentScan annotations with their default attributes. The default value for #ComponentScan means that all the sub packages on the package the #ComponentScan is used are scanned. That is why it is usually a good practice to include the main class in the base package of the project, so please make sure it is located there.
Having written this, try the following (drop scanBasePackages attribute and #ComponentScan annotation):
#SpringBootApplication
public class MySecureApplication {
public static void main(String[] args) {
SpringApplication.run(MySecureApplication.class, args);
}
}
#Configuration
#EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
}

Repository class require bean entityManagerFactory could not be found

I am making a angular + spring application in and was trying to deploy it in same server. when i created back-end separately it worked fine all the process was working. but when i copied my angular project in spring project and configured in pom.xml and updated my maven and tried running the project it started giving me below error
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-24 16:13:29.074 INFO 3136 --- [ main]
com.accounts.rtgsneft.Application : Starting Application on HO-W-
Ankushpc with PID 3136 (D:\Rocky\workspaces\acounts-projects\rtgs-neft-
v1.0\target\classes started by Rocky in D:\Rocky\workspaces\acounts-
projects\rtgs-neft-v1.0)
2019-09-24 16:13:29.076 INFO 3136 --- [ main]
com.accounts.rtgsneft.Application : No active profile set, falling
back to default profiles: default
2019-09-24 16:13:29.530 INFO 3136 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data
repositories in DEFAULT mode.
2019-09-24 16:13:29.584 INFO 3136 --- [ main] .
s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository
scanning in 48ms. Found 4 repository interfaces.
2019-09-24 16:13:29.910 INFO 3136 --- [ main]
trationDelegate$BeanPostProcessorChecker : Bean
'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$3c9c44bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-24 16:13:30.143 INFO 3136 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8086 (http)
2019-09-24 16:13:30.160 INFO 3136 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-24 16:13:30.160 INFO 3136 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-24 16:13:30.264 INFO 3136 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-24 16:13:30.264 INFO 3136 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1158 ms
2019-09-24 16:13:30.399 WARN 3136 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beneficiaryController': Unsatisfied dependency expressed through field 'beneficiaryService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beneficiaryMasterServiceImpl': Unsatisfied dependency expressed through field 'beneficiaryRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beneficiaryMasterRepository': Cannot create inner bean '(inner bean)#3ac04654' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3ac04654': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2019-09-24 16:13:30.402 INFO 3136 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-09-24 16:13:30.416 INFO 3136 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run
your application with 'debug' enabled.
2019-09-24 16:13:30.465 ERROR 3136 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field beneficiaryRepo in
com.accounts.rtgsneft.service.BeneficiaryMasterServiceImpl required a bean
named 'entityManagerFactory' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
i have tried all the solution on stack but none of them worked.
this are the solutions i have tried:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled
Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument
bean named 'entityManagerFactory' could not be found
Spring Boot - repository field required a bean named 'entityManagerFactory' that could not be found
Field repository required a bean named 'entityManagerFactory' that could not be found
Spring data jpa- No bean named 'entityManagerFactory' is defined; Injection of autowired dependencies failed
this is the solution i tried while debugging.
getDeclaredConstructors0(boolean)- line not available during tomcat startup in debug mode
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.1.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.accounts.rtgsneft</groupId>
<artifactId>rtgsneft</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rtgsneft</name>
<description>Gold's Gym Account department rtgs neft software</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/resources/static/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/rtgs-neft/dist/rtgs-neft</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
my BeneficiaryController .java
package com.accounts.rtgsneft.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
import com.accounts.rtgsneft.service.BeneficiaryMasterService;
/**
* #author Rocky
*
*/
#CrossOrigin(origins = "*", maxAge = 3600)
#RestController
#RequestMapping("beneficiary")
public class BeneficiaryController {
#Autowired
BeneficiaryMasterService beneficiaryService;
#GetMapping("all-beneficiary")
public ResponseEntity<?> getBeneficiaries() {
List<BeneficiaryMaster> beneficiaries = beneficiaryService.gettingBeneficiaries();
return new ResponseEntity<>(beneficiaries, HttpStatus.OK);
}
#PostMapping("new-beneficiary")
public ResponseEntity<?> postBeneficiary(#RequestBody BeneficiaryMaster beneficiary) {
boolean beneficiaryRegistered = beneficiaryService.registerBeneficiary(beneficiary);
return new ResponseEntity<>(beneficiaryRegistered, HttpStatus.OK);
}
#PostMapping("single-beneficiary")
public ResponseEntity<?> selectedBeneficiary(#RequestBody BeneficiaryMaster beneficiaryOBJ) {
BeneficiaryMaster beneficiary = beneficiaryService.getBeneficiary(beneficiaryOBJ.getAccountNumber());
return new ResponseEntity<>(beneficiary, HttpStatus.OK);
}
}
my BeneficiaryMasterService.java
package com.accounts.rtgsneft.service;
import java.util.List;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
public interface BeneficiaryMasterService {
List<BeneficiaryMaster> gettingBeneficiaries();
boolean registerBeneficiary(BeneficiaryMaster beneficiary);
BeneficiaryMaster getBeneficiary(Long accountNumber);
}
my BeneficiaryMasterServiceImpl.java
package com.accounts.rtgsneft.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
import com.accounts.rtgsneft.repos.BeneficiaryMasterRepository;
#Service
public class BeneficiaryMasterServiceImpl implements BeneficiaryMasterService {
#Autowired
BeneficiaryMasterRepository beneficiaryRepo;
#Override
public List<BeneficiaryMaster> gettingBeneficiaries() {
return beneficiaryRepo.findAll();
}
#Override
public boolean registerBeneficiary(BeneficiaryMaster beneficiary) {
boolean benficiaryStatusFlag = false;
BeneficiaryMaster benficiaryStatus= beneficiaryRepo.save(beneficiary);
if(benficiaryStatus != null ) {
benficiaryStatusFlag = true;
}
return benficiaryStatusFlag;
}
#Override
public BeneficiaryMaster getBeneficiary(Long accountNumber) {
return beneficiaryRepo.getOne(accountNumber);
}
}
my BeneficiaryMasterRepository.java
package com.accounts.rtgsneft.repos;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
#Repository
public interface BeneficiaryMasterRepository extends
JpaRepository<BeneficiaryMaster, Long> {}
I hope this much data is enough to find out the issue.
If there is any other solution please recommend it to me.
I'm using spring 2.17
I want to deploy the application war file in tomcat and before doing that i have to test it for checking whether it's still working or not.
Spring Data JPA by default looks for an EntityManagerFactory named entityManagerFactory. Check out this part of the Javadoc of EnableJpaRepositories or Table 2.1 of the Spring Data JPA documentation.
That means that you either have to rename your emf bean to entityManagerFactory or change your Spring configuration to:
(if you are using XML)
or
#EnableJpaRepositories(basePackages="your.package", entityManagerFactoryRef="emf")
(if you are using Java Config)

spring boot application failed to autowired feign client

I created a sample project of Spring Boot to understand the Feign client functionality, when run it gives below error.
Field remoteCallClient in com.example.demo.RestClient required a bean of type 'com.example.demo.RemoteCallClient' that could not be found.
Action:
Consider defining a bean of type 'com.example.demo.RemoteCallClient' in your configuration.
I tried various ways but it could not be resolved, provided the entire source code of the sample project.
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mictro-service-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>micro-service-3</name>
<description>Demo project for Spring Boot</description>
<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>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.5.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>
</project>
Application's main class
#SpringBootApplication
#EnableFeignClients
public class MicroService3Application {
public static void main(String[] args) {
SpringApplication.run(MicroService3Application.class, args);
}
}
Feign client
#FeignClient(url="https://jsonplaceholder.typicode.com/",value="USERS")
public interface RemoteCallClient {
#RequestMapping("users")
public String getUsers();
}
Rest controller
#RestController
public class RestClient {
#Autowired
private RemoteCallClient remoteCallClient;
public String getRemoteClient() {
return remoteCallClient.getUsers();
}
}
}
Logs
2018-07-23 11:22:57.668 INFO 6556 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#4efbca5a: startup date [Mon Jul 23 11:22:57 PDT 2018]; root of context hierarchy
2018-07-23 11:22:57.852 INFO 6556 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-07-23 11:22:57.877 INFO 6556 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$62660f56] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.3.RELEASE)
2018-07-23 11:22:58.066 INFO 6556 --- [ main] c.example.demo.MicroService3Application : No active profile set, falling back to default profiles: default
2018-07-23 11:22:58.075 INFO 6556 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#6b58b9e9: startup date [Mon Jul 23 11:22:58 PDT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#4efbca5a
2018-07-23 11:22:58.712 INFO 6556 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=27c00c1a-419a-35b3-9b1b-f3a4f9bbf439
2018-07-23 11:22:58.726 INFO 6556 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-07-23 11:22:58.800 INFO 6556 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$62660f56] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-23 11:22:58.992 INFO 6556 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-07-23 11:22:59.006 INFO 6556 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-07-23 11:22:59.006 INFO 6556 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-23 11:22:59.009 INFO 6556 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_92\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_92/bin/server;C:/Program Files/Java/jre1.8.0_92/bin;C:/Program Files/Java/jre1.8.0_92/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_92\bin;C:\Program Files (x86)\Skype\Phone\;C:\apache-tomcat\bin\;F:\apache-maven-3.5.0\bin;;E:\eclipse\oxygen\eclipse;;.]
2018-07-23 11:22:59.165 INFO 6556 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-07-23 11:22:59.165 INFO 6556 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1090 ms
2018-07-23 11:22:59.371 WARN 6556 --- [ost-startStop-1] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2018-07-23 11:22:59.371 INFO 6556 --- [ost-startStop-1] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2018-07-23 11:22:59.379 INFO 6556 --- [ost-startStop-1] c.netflix.config.DynamicPropertyFactory : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration#156f04f8
2018-07-23 11:23:00.180 INFO 6556 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-07-23 11:23:00.183 INFO 6556 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-23 11:23:00.184 INFO 6556 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-23 11:23:00.184 INFO 6556 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-23 11:23:00.184 INFO 6556 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-23 11:23:00.184 INFO 6556 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
2018-07-23 11:23:00.184 INFO 6556 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2018-07-23 11:23:00.209 WARN 6556 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'restClient': Unsatisfied dependency expressed through field 'remoteCallClient'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.demo.RemoteCallClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
2018-07-23 11:23:00.210 WARN 6556 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method 'close' failed on bean with name 'eurekaRegistration': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
2018-07-23 11:23:00.212 INFO 6556 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-07-23 11:23:00.225 INFO 6556 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-07-23 11:23:00.353 ERROR 6556 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field remoteCallClient in com.example.demo.RestClient required a bean of type 'com.example.demo.RemoteCallClient' that could not be found.
Action:
Consider defining a bean of type 'com.example.demo.RemoteCallClient' in your configuration.
For those, who included the Openfeign dependency and the feign client still cannot be autowired...
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
You have to also include the #EnableFeignClients configuration annotation which scans for the #FeignClient interfaces. Otherwise these clients remain ignored.
#EnableFeignClients
#SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication .class, args);
}
}
Use below Feign Dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
Make sure RemoteCallClient is not in different package than main application class. if it is added #ComponentScan("package")
I was battling the similar issue. I see that you already have spring-cloud-starter-openfeign dependency. I recommend that you remove the older feign dependency that exists in your POM spring-cloud-starter-feign 1.4.5.RELEASE. If your feignClient resides in a different app then upgrade both apps to be on similar to be on same versions. That worked for me. Hope it works for you!
I am using
spring-boot-starter-parent 2.1.2.RELEASE
spring-cloud-dependencies Greenwich.RELEASE
and have the following in my dependencies
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Spting cloud data flow batch job is running one time if #EnableTask is used in main app

Hi I am trying to deploy simple spring boot batch jar file in local spring cloud data flow server. I am facing serious problem in the batch when I am using #EnableTask in my main java class. When I am using #EnableTask in my application the batch job is running only one time. Its executing the batch and then de registering the application automatically. Code for the application is given below.
1)main class
package com.jwt.spring.batch;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.task.configuration.EnableTask;
#EnableTask
#EnableBatchProcessing
#SpringBootApplication
public class ScdfBatchApplication {
public static void main(String[] args) {
SpringApplication.run(ScdfBatchApplication.class, args);
}
}
2)JobConfiguration.java
package com.jwt.spring.batch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
public class JobConfiguration {
private static final Log logger = LogFactory.getLog(JobConfiguration.class);
#Autowired
public JobBuilderFactory jobBuilderFactory;
#Autowired
public StepBuilderFactory stepBuilderFactory;
#Bean
public Job job() {
return jobBuilderFactory.get("job").start(stepBuilderFactory.get("jobStep1").tasklet(new Tasklet() {
#Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
logger.info("Job was run");
return RepeatStatus.FINISHED;
}
}).build()).build();
}
}
3)pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jwt.spring.batch</groupId>
<artifactId>SCDFBatch</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SCDFBatch</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.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>
<spring-cloud-task.version>1.2.2.RELEASE</spring-cloud-task.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-task</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</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.batch</groupId>
<artifactId>spring-batch-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-dependencies</artifactId>
<version>${spring-cloud-task.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>
Below is the log of the application
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.9.RELEASE)
2018-01-05 17:13:37.984 INFO 14436 --- [ main] c.jwt.spring.batch.ScdfBatchApplication : Starting ScdfBatchApplication on bdc7-l-5065XBS with PID 14436 (C:\STS-WORK_SPACE\SPRING-BATCH\SCDFBatch\target\classes started by mukesh.bo.kumar in C:\STS-WORK_SPACE\SPRING-BATCH\SCDFBatch)
2018-01-05 17:13:37.990 INFO 14436 --- [ main] c.jwt.spring.batch.ScdfBatchApplication : No active profile set, falling back to default profiles: default
2018-01-05 17:13:38.091 INFO 14436 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#9e725a: startup date [Fri Jan 05 17:13:38 IST 2018]; root of context hierarchy
2018-01-05 17:13:39.153 INFO 14436 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'transactionManager' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.task.configuration.SimpleTaskConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in org.springframework.cloud.task.configuration.SimpleTaskConfiguration] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]]
2018-01-05 17:13:39.784 WARN 14436 --- [ 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.
2018-01-05 17:13:39.804 WARN 14436 --- [ 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.
2018-01-05 17:13:39.943 INFO 14436 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.task.batch.configuration.TaskBatchAutoConfiguration' of type [org.springframework.cloud.task.batch.configuration.TaskBatchAutoConfiguration$$EnhancerBySpringCGLIB$$e6554726] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-05 17:13:39.952 INFO 14436 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$60e59b9a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-05 17:13:40.005 INFO 14436 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.task.batch.listener.BatchEventAutoConfiguration' of type [org.springframework.cloud.task.batch.listener.BatchEventAutoConfiguration$$EnhancerBySpringCGLIB$$2eab5129] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-01-05 17:13:40.955 INFO 14436 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2018-01-05 17:13:40.971 INFO 14436 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-01-05 17:13:40.972 INFO 14436 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
2018-01-05 17:13:41.201 INFO 14436 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-01-05 17:13:41.202 INFO 14436 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3116 ms
2018-01-05 17:13:41.540 INFO 14436 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-01-05 17:13:41.544 INFO 14436 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-05 17:13:41.545 INFO 14436 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-01-05 17:13:41.545 INFO 14436 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-01-05 17:13:41.545 INFO 14436 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-01-05 17:13:42.681 INFO 14436 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [org/springframework/cloud/task/schema-h2.sql]
2018-01-05 17:13:42.726 INFO 14436 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [org/springframework/cloud/task/schema-h2.sql] in 45 ms.
2018-01-05 17:13:43.076 INFO 14436 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#9e725a: startup date [Fri Jan 05 17:13:38 IST 2018]; root of context hierarchy
2018-01-05 17:13:43.170 INFO 14436 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-01-05 17:13:43.172 INFO 14436 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-01-05 17:13:43.206 INFO 14436 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-05 17:13:43.207 INFO 14436 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-05 17:13:43.314 INFO 14436 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-01-05 17:13:43.415 INFO 14436 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [org/springframework/batch/core/schema-h2.sql]
2018-01-05 17:13:43.435 INFO 14436 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [org/springframework/batch/core/schema-h2.sql] in 20 ms.
2018-01-05 17:13:43.592 INFO 14436 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-01-05 17:13:43.603 INFO 14436 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2018-01-05 17:13:43.721 INFO 14436 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-01-05 17:13:43.725 INFO 14436 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: []
2018-01-05 17:13:43.730 INFO 14436 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: H2
2018-01-05 17:13:43.913 INFO 14436 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2018-01-05 17:13:43.961 INFO 14436 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job]] launched with the following parameters: [{}]
2018-01-05 17:13:43.972 INFO 14436 --- [ main] o.s.c.t.b.l.TaskBatchExecutionListener : The job execution id 1 was run within the task execution 1
2018-01-05 17:13:43.981 INFO 14436 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [jobStep1]
2018-01-05 17:13:43.992 INFO 14436 --- [ main] com.jwt.spring.batch.JobConfiguration : Job was run
2018-01-05 17:13:43.998 INFO 14436 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-01-05 17:13:44.003 INFO 14436 --- [ main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#9e725a: startup date [Fri Jan 05 17:13:38 IST 2018]; root of context hierarchy
2018-01-05 17:13:44.004 INFO 14436 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2018-01-05 17:13:44.005 INFO 14436 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-01-05 17:13:44.278 INFO 14436 --- [ main] c.jwt.spring.batch.ScdfBatchApplication : Started ScdfBatchApplication in 6.956 seconds (JVM running for 9.208)
Please this post. You need to use the RunIdIncrementer in your job.
Spring Batch Item Reader is executing only once
First thing Please add timestamp to name of the Job to make it unique everytime its being run.
Secondly, you should use task-launcher or stream to launch your task run more than once.
Launch it using TriggerTask; with this you could either choose to launch it with fixedDelay or via a cron expression
Finally if you wanted job to be running based on some event then create and deploy your spring batch job as stream rather than deploying as task. What type of stream depends upon your requirement whether it is processor or sink. As per the details in your query, its more kind of processor hence reference examples from spring cloud stream related to processor, have pasted a sample processor application code.
Please refer https://github.com/spring-cloud/spring-cloud-stream-samples/tree/master/transform

Resources