In my case, I'm implementing batch program that manages dormant accounts
My problem is this. The internal logic of the processor and the writer is not executed.
First of all, I thought about why the processor is not working. After thinking for a long time, I thought that the logic in the processor was not implemented because the data that the reader brought was not transferred to the processor.
For example, In for If the size of the repeat statement is 0, the repeat statement does not rotate at all
Usually, when transferring data from a function to a function, a parameter is used, but there is no such parameter in a batch
That's why I'm posting questions. I wonder how the data goes in order in the rotation of the batch leading to reader -> processor -> writer.
I think it's like bringing Step to StepBuilder and putting reader, processor, and writer together in one bundle and sending and receiving data in it. It is right?
Below is my code that has a problem. Please check if there is a problem with the report.
package com.capston.chatting.config.batch;
import com.capston.chatting.entity.Member;
import com.capston.chatting.enums.MemberStatus;
import com.capston.chatting.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
#Slf4j
#RequiredArgsConstructor
#Configuration
public class InactiveMemberJobConfig {
private final MemberRepository memberRepository;
private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;
#Bean
public Job inactiveMemberJob() {
return jobBuilderFactory.get("inactiveMemberJob3")
.start(inactiveJobStep())
.build();
}
#Bean
public Step inactiveJobStep() {
return stepBuilderFactory.get("inactiveMemberStep")
.<Member, Member>chunk(10)
.reader(inactiveMemberReader())
.processor(inactiveMemberProcessor())
.writer(inactiveMemberWriter())
.allowStartIfComplete(true)
.build();
}
#Bean
public ListItemReader<Member> inactiveMemberReader() {
log.info("InactiveMemberReader execution");
List<Member> oldMembers = memberRepository
.findByUpdateDateBeforeAndStatusEquals(LocalDateTime.now().minusYears(1), MemberStatus.ACTIVE);
ArrayList<Member> collect = oldMembers.stream().map(member -> member.setInactive()).collect(Collectors.toCollection(ArrayList::new));
memberRepository.saveAll(collect);
return new ListItemReader<>(oldMembers);
}
#Bean
public ItemProcessor<Member, Member> inactiveMemberProcessor() {
log.info("test");
ItemProcessor<Member, Member> memberItemProcessor = (member) -> { // dose not working
log.info("InactiveMemberProcessor execution");
return member.setInactive();
};
return memberItemProcessor;
// return new ItemProcessor<Member, Member>() { // dose not working
// #Override
// public Member process(Member member) throws Exception {
// log.info("InactiveMemberProcessor execution");
// return member.setInactive();
// }
// };
// return member -> { // does not working
// log.info("InactiveMemberProcessor 작동");
// return member.setInactive();
// };
}
#Bean
public ItemWriter<Member> inactiveMemberWriter() {
log.info("InactiveMemberWriter execution");
return ((List<? extends Member> members) -> {
memberRepository.saveAll(members);
log.info("Members : {}", members);
});
}
}
Output
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.2)
2022-08-22 21:57:29.812 INFO 18204 --- [ restartedMain] c.capston.chatting.ChattingApplication : Starting ChattingApplication using Java 11.0.12 on DESKTOP-SHB62PK with PID 18204 (D:\chatting\chatting\build\classes\java\main started by user in D:\chatting\chatting)
2022-08-22 21:57:29.813 INFO 18204 --- [ restartedMain] c.capston.chatting.ChattingApplication : The following 4 profiles are active: "google", "naver", "kakao", "local"
2022-08-22 21:57:29.835 INFO 18204 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-08-22 21:57:29.835 INFO 18204 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-08-22 21:57:30.203 INFO 18204 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-08-22 21:57:30.235 INFO 18204 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 28 ms. Found 4 JPA repository interfaces.
2022-08-22 21:57:30.549 INFO 18204 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-08-22 21:57:30.554 INFO 18204 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-08-22 21:57:30.554 INFO 18204 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-08-22 21:57:30.626 INFO 18204 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-08-22 21:57:30.626 INFO 18204 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 791 ms
2022-08-22 21:57:30.669 INFO 18204 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-08-22 21:57:30.812 INFO 18204 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-08-22 21:57:30.870 INFO 18204 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-08-22 21:57:30.892 INFO 18204 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
2022-08-22 21:57:30.970 INFO 18204 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-08-22 21:57:31.021 INFO 18204 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2022-08-22 21:57:31.272 INFO 18204 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-08-22 21:57:31.276 INFO 18204 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-08-22 21:57:31.700 INFO 18204 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter#62d2016, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#62c4efa9, org.springframework.security.web.context.SecurityContextPersistenceFilter#56b3c5da, org.springframework.security.web.header.HeaderWriterFilter#266f4945, org.springframework.security.web.authentication.logout.LogoutFilter#73659a41, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#3cc99087, org.springframework.security.web.session.ConcurrentSessionFilter#52b3aca9, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#44b457bc, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#16cb2cdf, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#fd87fe6, org.springframework.security.web.session.SessionManagementFilter#5f5bda7b, org.springframework.security.web.access.ExceptionTranslationFilter#612557ba, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#19931dcc]
2022-08-22 21:57:31.707 INFO 18204 --- [ restartedMain] c.c.c.c.batch.InactiveMemberJobConfig : InactiveMemberReader execution
2022-08-22 21:57:31.724 DEBUG 18204 --- [ restartedMain] org.hibernate.SQL :
select
member0_.member_id as member_i1_3_,
member0_.created_date as created_2_3_,
member0_.login_id as login_id3_3_,
member0_.login_pw as login_pw4_3_,
member0_.name as name5_3_,
member0_.role as role6_3_,
member0_.score as score7_3_,
member0_.status as status8_3_,
member0_.update_date as update_d9_3_
from
member member0_
where
member0_.update_date<?
and member0_.status=?
2022-08-22 21:57:31.765 WARN 18204 --- [ restartedMain] o.s.b.a.batch.JpaBatchConfigurer : JPA does not support custom isolation levels, so locks may not be taken when launching Jobs. To silence this warning, set 'spring.batch.jdbc.isolation-level-for-create' to 'default'.
2022-08-22 21:57:31.767 INFO 18204 --- [ restartedMain] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: MYSQL
2022-08-22 21:57:31.774 INFO 18204 --- [ restartedMain] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2022-08-22 21:57:31.807 INFO 18204 --- [ restartedMain] c.c.c.c.batch.InactiveMemberJobConfig : test // next step is "InactiveMemberProceesor execution" log but not happened
2022-08-22 21:57:31.807 INFO 18204 --- [ restartedMain] c.c.c.c.batch.InactiveMemberJobConfig : InactiveMemberWriter execution
2022-08-22 21:57:32.001 INFO 18204 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-08-22 21:57:32.022 INFO 18204 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-08-22 21:57:32.024 INFO 18204 --- [ restartedMain] o.s.m.s.b.SimpleBrokerMessageHandler : Starting...
2022-08-22 21:57:32.024 INFO 18204 --- [ restartedMain] o.s.m.s.b.SimpleBrokerMessageHandler : BrokerAvailabilityEvent[available=true, SimpleBrokerMessageHandler [org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry#6a114117]]
2022-08-22 21:57:32.024 INFO 18204 --- [ restartedMain] o.s.m.s.b.SimpleBrokerMessageHandler : Started.
2022-08-22 21:57:32.029 INFO 18204 --- [ restartedMain] c.capston.chatting.ChattingApplication : Started ChattingApplication in 2.431 seconds (JVM running for 2.948)
2022-08-22 21:57:32.030 INFO 18204 --- [ restartedMain] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: []
2022-08-22 21:57:32.451 INFO 18204 --- [ restartedMain] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=inactiveMemberJob3]] launched with the following parameters: [{}]
2022-08-22 21:57:32.731 INFO 18204 --- [ restartedMain] o.s.batch.core.job.SimpleStepHandler : Executing step: [inactiveMemberStep]
2022-08-22 21:57:32.938 INFO 18204 --- [ restartedMain] o.s.batch.core.step.AbstractStep : Step: [inactiveMemberStep] executed in 207ms
2022-08-22 21:57:33.098 INFO 18204 --- [ restartedMain] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=inactiveMemberJob3]] completed with the following parameters: [{}] and the following status: [COMPLETED] in 573ms
2022-08-22 21:58:31.637 INFO 18204 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 0]
2022-08-22 22:28:31.643 INFO 18204 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], sockJsScheduler[pool size = 2, active threads = 1, queued tasks = 0, completed tasks = 1]
2022-08-22 22:39:54.662 INFO 18204 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-08-22 22:39:54.662 INFO 18204 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-08-22 22:39:54.663 INFO 18204 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
The problem has been solved. In Step properties, the allowStartIfComplete property is given as true, so it works normally. But the question is still valid. I want to know how the data moves in the rotation of reader->processor->wrtier.
I deployed my spring boot project with jar file on my lightsail server. I think it deployed fine however, I can't access it.
Chrome says,
This site can’t be reached {ip} refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
internal tomcat log
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.0)
2022-06-21 05:37:40.476 INFO 7028 --- [ main] com.--Application : Starting MyApplication using Java 17.0.3 on ip-172-26-7-171 with PID 7028 (/home/ubuntu/My.jar started by root in /home/ubuntu)
2022-06-21 05:37:40.483 INFO 7028 --- [ main] com.--Application : The following 1 profile is active: "prod"
2022-06-21 05:37:42.758 INFO 7028 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-06-21 05:37:42.883 INFO 7028 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 100 ms. Found 1 JPA repository interfaces.
2022-06-21 05:37:44.472 INFO 7028 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 80 (http)
2022-06-21 05:37:44.501 INFO 7028 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-06-21 05:37:44.502 INFO 7028 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.63]
2022-06-21 05:37:44.694 INFO 7028 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-06-21 05:37:44.695 INFO 7028 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3508 ms
2022-06-21 05:37:45.661 INFO 7028 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-06-21 05:37:46.006 INFO 7028 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-06-21 05:37:46.121 INFO 7028 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-06-21 05:37:46.275 INFO 7028 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.9.Final
2022-06-21 05:37:46.658 INFO 7028 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-06-21 05:37:46.910 INFO 7028 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
2022-06-21 05:37:48.039 INFO 7028 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-06-21 05:37:48.055 INFO 7028 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-06-21 05:37:48.995 WARN 7028 --- [ 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-06-21 05:37:49.637 WARN 7028 --- [ main] org.thymeleaf.templatemode.TemplateMode : [THYMELEAF][main] Template Mode 'HTML5' is deprecated. Using Template Mode 'HTML' instead.
2022-06-21 05:37:50.173 INFO 7028 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter#3d1f558a, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#6abdec0e, org.springframework.security.web.context.SecurityContextPersistenceFilter#3762c4fc, org.springframework.security.web.header.HeaderWriterFilter#4b4ee511, org.springframework.security.web.csrf.CsrfFilter#38f77cd9, org.springframework.security.web.authentication.logout.LogoutFilter#2ae62bb6, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#5762658b, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#6ca372ef, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#28f4f300, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#6aa3bfc, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#59fbb34, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#1b6924cb, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#2b5c4f17, org.springframework.security.web.session.SessionManagementFilter#5a034157, org.springframework.security.web.access.ExceptionTranslationFilter#4483d35, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#6fc1020a]
2022-06-21 05:37:50.300 INFO 7028 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 80 (http) with context path ''
2022-06-21 05:37:50.332 INFO 7028 --- [ main] com.--Application : Started MyApplication in 10.965 seconds (JVM running for 12.248)
This is my firewall settings on lightsail.
/home/ubuntu# lsof -i -nP | grep LISTEN | awk '{print $(NF-1)" "$1}' | sort -u
*:22 sshd
127.0.0.1:33060 ssh
127.0.0.1:80 java
127.0.0.53:53 systemd-r
Do I have to edit firewall setting?
I remove server.address=localhost from application.properties and it works well.
I have a jar file, which was built using maven (the app is spring-boot). I deployed it on a remote server using nohup java -jar app.jar command. It works for a day or so and then stops working. The logs in nohup file are not informative and I could not figure out what's the reason for that. By stops working, I mean - the application just terminates, it is not working.
Here is the output of the nohup file:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.1)
2022-02-21 06:19:32.288 INFO 74013 --- [ main] kz.iuth.platonus.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 1.8.0_131 on user-ProLiant-ML30-Gen9 with PID 74013 (/home/user/iuth_app/demo-0.0.1-SNAPSHOT.jar started by user in /home/user/iuth_app)
2022-02-21 06:19:32.290 INFO 74013 --- [ main] kz.iuth.platonus.demo.DemoApplication : No active profile set, falling back to default profiles: default
2022-02-21 06:19:32.913 INFO 74013 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-02-21 06:19:32.981 INFO 74013 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 60 ms. Found 11 JPA repository interfaces.
2022-02-21 06:19:33.485 INFO 74013 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http)
2022-02-21 06:19:33.497 INFO 74013 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-02-21 06:19:33.497 INFO 74013 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.55]
2022-02-21 06:19:33.545 INFO 74013 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-02-21 06:19:33.545 INFO 74013 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1209 ms
2022-02-21 06:19:33.691 INFO 74013 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-02-21 06:19:34.035 INFO 74013 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-02-21 06:19:34.074 INFO 74013 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-02-21 06:19:34.115 INFO 74013 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.1.Final
2022-02-21 06:19:34.249 INFO 74013 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-02-21 06:19:34.348 INFO 74013 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
2022-02-21 06:19:34.819 INFO 74013 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-02-21 06:19:34.826 INFO 74013 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-02-21 06:19:35.564 WARN 74013 --- [ 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-21 06:19:36.010 INFO 74013 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9090 (http) with context path ''
2022-02-21 06:19:36.018 INFO 74013 --- [ main] kz.iuth.platonus.demo.DemoApplication : Started DemoApplication in 4.109 seconds (JVM running for 4.502)
2022-02-21 06:19:53.481 INFO 74013 --- [nio-9090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-02-21 06:19:53.481 INFO 74013 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-02-21 06:19:53.493 INFO 74013 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2022-02-21 06:19:58.354 WARN 74013 --- [nio-9090-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
.....
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.55.jar!/:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.55.jar!/:na]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
2022-02-21 23:08:17.439 WARN 74013 --- [nio-9090-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
2022-02-21 23:30:31.755 INFO 74013 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-02-21 23:30:31.762 INFO 74013 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-02-21 23:30:31.769 INFO 74013 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
I'm not sure what's the problem. Please, feel free to ask more information, If you need and I will edit.
My Spring Boot Application connects to a PostgreSQL database but it didn't create the tables which i have implemented as entities. That's why I set up the tables by myself with test data.
When I use dataRepository.findAll() to access the data, it returns an empty list.
So as far as I understood, I think it connects to my database, because I get no errors, but it looks like the schemas don't work properly.
I'm pretty sure this is a "configuration" problem, but I was not able to figure out what it is.
PS: I have another project with quite the same settings and code(just another database on the same server) which works perfectly fine.
My gradle.build file:
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'de.dari'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8'
repositories {
mavenCentral()
maven { url "http://htmlunit.sourceforge.net" }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
//implementation 'org.springframework.boot:spring-boot-starter-data-rest'
compile("net.sourceforge.htmlunit:htmlunit:2.35.0")
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
My application.properties file:
spring.datasource.url=jdbc:postgresql://webaddress.com:5432/b-one
spring.datasource.username=username
spring.datasource.password=secretPassword
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
An Example Entity:
#Entity
public class Data {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
private String value;
/*
* Blank Constructor + Getters and Setters down here
*/
}
Simple CRUD-Repository:
public interface DataRepository extends CrudRepository<Data, Long> {
}
Controller:
#Autowired
DataRepository dataRepository;
#GetMapping("/test")
public String test() {
return dataRepository.findAll().toString();
}
Yeah so I don't get any error messages and the logs weren't helpful for me but maybe you want to get a glimpse on them.
Console-Output:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2019-08-26 16:23:53.225 INFO 10220 --- [ main] de.dari.bone.REST.Application : Starting Application on GamingPC with PID 10220 (started by Deniz Cuhadari in C:\Users\Deniz Cuhadari\OneDrive - inc\Projects\b-one\b-one.REST)
2019-08-26 16:23:53.230 INFO 10220 --- [ main] de.dari.bone.REST.Application : No active profile set, falling back to default profiles: default
2019-08-26 16:23:54.083 INFO 10220 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-26 16:23:54.202 INFO 10220 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 110ms. Found 6 repository interfaces.
2019-08-26 16:23:54.568 INFO 10220 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$24d7df9e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-26 16:23:54.878 INFO 10220 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-26 16:23:54.907 INFO 10220 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-26 16:23:54.908 INFO 10220 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-08-26 16:23:55.057 INFO 10220 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-26 16:23:55.057 INFO 10220 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1757 ms
2019-08-26 16:23:55.226 INFO 10220 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-08-26 16:23:55.650 INFO 10220 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-08-26 16:23:55.711 INFO 10220 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-08-26 16:23:55.793 INFO 10220 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final}
2019-08-26 16:23:55.795 INFO 10220 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-08-26 16:23:55.947 INFO 10220 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-08-26 16:23:56.098 INFO 10220 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2019-08-26 16:24:02.271 INFO 10220 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000421: Disabling contextual LOB creation as hibernate.jdbc.lob.non_contextual_creation is true
2019-08-26 16:24:02.278 INFO 10220 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType#7e49ded
2019-08-26 16:24:03.329 INFO 10220 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-08-26 16:24:03.946 INFO 10220 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-26 16:24:03.987 WARN 10220 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : 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
2019-08-26 16:24:04.051 INFO 10220 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2019-08-26 16:24:04.162 INFO 10220 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-08-26 16:24:04.165 INFO 10220 --- [ main] de.dari.bone.REST.Application : Started Application in 11.503 seconds (JVM running for 12.75)
2019-08-26 16:24:09.762 INFO 10220 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-08-26 16:24:09.762 INFO 10220 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-08-26 16:24:09.769 INFO 10220 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 7 ms
2019-08-26 16:24:09.905 INFO 10220 --- [nio-8080-exec-1] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
I´m starting with Spring Boot for that I´m following a tutorial. In the tutorial, they created the controller with the #RequestMapping and GET method, once they have run the application, in the console is displayed something like this:
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/rooms], methods
= GET}" onto java.util.List<..//more lines
But in my case I got an error:
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto
public
org.springframework.http.ResponseEntity>
org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
Why the Mapping is not created?
This is the controller:
package com.frankmoley.london.data.webservice;
import com.frankmoley.london.data.entity.Room;
import com.frankmoley.london.data.repository.RoomRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
#RestController
public class RoomController {
#Autowired
private RoomRepository repository;
#RequestMapping(value="/rooms", method= RequestMethod.GET)
List<Room> findAll(#RequestParam(required=false) String roomNumber){
List<Room> rooms = new ArrayList<>();
if(null==roomNumber){
Iterable<Room> results = this.repository.findAll();
results.forEach(room-> {rooms.add(room);});
}else{
Room room = this.repository.findByNumber(roomNumber);
if(null!=room) {
rooms.add(room);
}
}
return rooms;
}
}
Entity:
package com.frankmoley.london.data.entity;
import javax.persistence.*;
#Entity
#Table(name = "ROOM")
public class Room {
#Id
#Column(name = "ROOM_ID")
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
#Column(name = "NAME")
private String name;
#Column(name = "ROOM_NUMBER")
private String number;
#Column(name = "BED_INFO")
private String info;
//getters and setters
}
Repository:
package com.frankmoley.london.data.repository;
import com.frankmoley.london.data.entity.Room;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
#Repository
public interface RoomRepository extends CrudRepository<Room, Long> {
Room findByNumber(String number);
}
Following are my logs:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-09 21:41:37.074 INFO 25569 --- [ main] SpringRest.spring_rest.Application : Starting Application on prashant-ubuntu with PID 25569 (/home/prashant/workspace/egen/spring-rest/target/spring-rest-1.0.0.jar started by prashant in /home/prashant/workspace/egen/spring-rest/target)
2019-09-09 21:41:37.077 INFO 25569 --- [ main] SpringRest.spring_rest.Application : No active profile set, falling back to default profiles: default
2019-09-09 21:41:37.715 INFO 25569 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-09 21:41:37.796 INFO 25569 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 68ms. Found 1 repository interfaces.
2019-09-09 21:41:38.389 INFO 25569 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$d6eeeeff] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-09 21:41:38.696 INFO 25569 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-09-09 21:41:38.735 INFO 25569 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-09 21:41:38.735 INFO 25569 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-09 21:41:38.837 INFO 25569 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-09 21:41:38.837 INFO 25569 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1701 ms
2019-09-09 21:41:39.124 INFO 25569 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-09-09 21:41:39.415 INFO 25569 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-09-09 21:41:39.463 INFO 25569 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-09-09 21:41:39.525 INFO 25569 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.11.Final}
2019-09-09 21:41:39.526 INFO 25569 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-09-09 21:41:39.662 INFO 25569 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-09-09 21:41:39.866 INFO 25569 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-09-09 21:41:40.463 INFO 25569 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2019-09-09 21:41:40.559 INFO 25569 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-09 21:41:41.041 INFO 25569 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-09 21:41:41.114 WARN 25569 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : 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
2019-09-09 21:41:41.380 INFO 25569 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-09-09 21:41:41.382 INFO 25569 --- [ main] SpringRest.spring_rest.Application : Started Application in 4.703 seconds (JVM running for 5.103)
2019-09-09 21:42:03.922 INFO 25569 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-09 21:42:03.922 INFO 25569 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-09-09 21:42:03.934 INFO 25569 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 12 ms
Hibernate: select employee0_.id as id1_0_, employee0_.email as email2_0_, employee0_.name as name3_0_, employee0_.salary as salary4_0_ from employee employee0_
you can clearly see that there aren't any references of RequestMappingHandlerMapping
But still the service is hosted at "/".
I have used the following URL:
http://localhost:8080/employees/springEntityManagerJpa
With other spring application which is not spring boot, the URL is as follows:
http://localhost:8080/spring-rest/api/employees/springEntityManagerJpa
I assume your is the similar case. May be the service is up, but you are providing the wrong endpoints. Just remove the context path. In my case I removed /spring-rest/api
Hope this helps!!!