[JAVA] A memo that I was addicted to when making batch processing with Spring Boot

When I tried to make a batch process with Springboot, I got stuck in the following, so make a note

  1. The created Repository cannot be read!

When I searched the net, it was said that ConfigurableApplicationContext should be used, so write as follows

package com;

import java.io.IOException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class SampleApplication {

	/**
 * Main class
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		try {

			ConfigurableApplicationContext context = SpringApplication.run(SampleBatchService.class, args);
			SampleBatchService service = context.getBean(SampleBatchService.class);
			service.run(args);
			context.close();

		} catch (IOException e) {
			e.printStackTrace();

		} catch (InterruptedException e) {
 // TODO auto-generated catch block
			e.printStackTrace();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

However, the error that Repository cannot be DI is ...

***************************
APPLICATION FAILED TO START
***************************

Description:

Field latestRateRepository in com.SampleApplication required a bean of type 'com.repository.LatestRateRepository' 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 of type 'com.repository.LatestRateRepository' in your configuration.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sampleBatchService': Unsatisfied dependency expressed through field 'latestRateRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.repository.LatestRateRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at com.SampleApplication.main(SampleApplication.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.repository.LatestRateRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1695)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1253)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
	... 23 more
org.springframework.boot.devtools.restart.SilentExitExceptionHandler$SilentExitException
	at org.springframework.boot.devtools.restart.SilentExitExceptionHandler.exitCurrentThread(SilentExitExceptionHandler.java:90)
	at org.springframework.boot.devtools.restart.Restarter.immediateRestart(Restarter.java:180)
	at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:164)
	at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:554)
	at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartingEvent(RestartApplicationListener.java:74)
	at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:50)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
	at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:70)
	at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at com.SampleApplication.main(SampleApplication.java:21)

After struggling for about 3 days, the class specified in ConfigurableApplicationContext was wrong in the main class. .. ..

ConfigurableApplicationContext context = SpringApplication.run(SampleBatchService.class, args);                                     ↓ ConfigurableApplicationContext context = SpringApplication.run(SampleApplication.class, args);

You have to specify your own class here: frowning2:

Recommended Posts

A memo that I was addicted to when making batch processing with Spring Boot
What I was addicted to when developing a Spring Boot application with VS Code
What I fixed when updating to Spring Boot 1.5.12 ・ What I was addicted to
A site that was easy to understand when I was a beginner when I started learning Spring Boot
A memo that touched Spring Boot
A story that stumbled when deploying a web application created with Spring Boot to EC2
When introducing JOOQ to Spring boot, a story that was dealt with because an error occurred around Liquibase
A story I was addicted to when getting a key that was automatically tried on MyBatis
How to batch initialize arrays in Java that I didn't know when I was a beginner
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
What I was addicted to when implementing google authentication with rails
A memo that was soberly addicted to the request of multipart / form-data
A story I was addicted to when testing the API using MockMVC
My.cnf configuration problem that I was addicted to when I was touching MySQL 8.0 like 5.7
Problems I was addicted to when building the digdag environment with docker
I was addicted to doing onActivityResult () with DialogFragment
I wanted to gradle spring boot with multi-project
A story that I was addicted to twice with the automatic startup setting of Tomcat 8 on CentOS 8
SpringSecurity I was addicted to trying to log in with a hashed password (solved)
I tried to clone a web application full of bugs with Spring Boot
A story that I was really into when I did triple DES with ruby
When internationalizing is supported by Spring Boot, a specific locale is not translated and I am addicted to it
A memorandum when creating a REST service with Spring Boot
I wrote a test with Spring Boot + JUnit 5 now
When making a personal app, I was wondering whether to make it using haml
What I was addicted to when trying to properly openAPI/Swagger documentation with Rails + Grape + Grape Swagger
What I was addicted to when introducing the JNI library
I was addicted to setting default_url_options with Rails devise introduction
A story I was addicted to in Rails validation settings
[Rails] I tried to implement batch processing with Rake task
What I was addicted to with the Redmine REST API
I tried to get started with Swagger using Spring Boot
The story I was addicted to when setting up STS
A note that I had trouble when trying to use nginx with Remote-Containers of vscode
When I personally developed with Rails, it was a painful story that Rails was hit very much
A story I was addicted to with implicit type conversion of ActiveRecord during unit testing
I was addicted to WSl when trying to build an android application development environment with Vue.js
Java: A story that made me feel uncomfortable when I was taught to compare strings with equals for no reason.
A story that I struggled to challenge a competition professional with Java
I get a 404 error when testing forms authentication with Spring Security
[MacOS] I was disturbed by ruby when installing Spring Boot CLI
Technical causes and countermeasures for the points that I was addicted to with the Android app & Kotlin (2. Processing related to the camera function of Android *)
[Ruby 3.0] A memo that I added a type definition to a library I wrote
Things to consider when running a specified job using Spring Batch
I was angry with proc_open (): fork failed when trying to composer update inside a Docker container
I made a simple search form with Spring Boot + GitHub Search API.
Sample code to unit test a Spring Boot controller with MockMvc
About the matter that I was addicted to how to use hashmap
I tried GraphQL with Spring Boot
[Rails] How to solve ActiveSupport :: MessageVerifier :: InvalidSignature that I was addicted to when introducing twitter login [ActiveStorage]
I tried Flyway with Spring Boot
It's not a big deal if you understand that I was addicted to receiving emails with Java Mail from Exchange Online
The story of making it possible to build a project that was built by Maven with Ant
Memorandum: What I was addicted to when I hit the accounting freee API
[Rails] I was addicted to the nginx settings when using Action Cable.
I was addicted to a simple test of Jedis (Java-> Redis library)
[iOS] I tried to make a processing application like Instagram with Swift
I was a little addicted to running old Ruby environment and old Rails
I tried to make a Web API that connects to DB with Quarkus
I used Docker to solidify the template to be developed with spring boot.
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]