Trace id propagation in Spring Boot 3 with Spring cloud streams and WebFlux - spring-boot

I tried to use spring cloud stream with kafka binder. But when I called WebClient in chain, then trace id is lost.
My flow is 'external service' -> 'functionStream-in' -> 'http call' -> functionStream-out' -> 'testStream-in' -> 'testStream-out' -> 'external service'
But after http call(or not?) the trace id is not propagated and I don't understand why. If I remove http call, then everything is OK.
I tried to add Hooks.enableAutomaticContextPropagation();, but that didn't help.
I tried to add ContextSnapshot.setThreadLocalsFrom around http call - same thing.
How can I solve it?
Dependencies:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.cloud:spring-cloud-stream'
implementation 'org.springframework.cloud:spring-cloud-starter-stream-kafka'
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation 'io.zipkin.reporter2:zipkin-reporter-brave'
implementation "io.projectreactor:reactor-core:3.5.3"
implementation "io.micrometer:context-propagation:1.0.2"
implementation "io.micrometer:micrometer-core:1.10.4"
implementation "io.micrometer:micrometer-tracing:1.0.2"
}
application.yml:
spring:
cloud.stream:
kafka.binder:
enableObservation: true
headers:
- b3
function.definition: functionStream;testStream
default.producer.useNativeEncoding: true
bindings:
functionStream-in-0:
destination: spring-in
group: spring-test1
functionStream-out-0:
destination: test-in
testStream-in-0:
destination: test-in
group: spring-test2
testStream-out-0:
destination: spring-out
integration:
management:
observation-patterns: "*"
kafka:
bootstrap-servers: localhost:9092
consumer:
auto-offset-reset: earliest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
properties:
spring.deserializer.value.delegate.class: org.apache.kafka.common.serialization.StringDeserializer
producer:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
management:
tracing:
enabled: true
sampling.probability: 1.0
propagation.type: b3
logging.pattern.level: "%5p [%X{traceId:-},%X{spanId:-}]"
Code:
#Bean
WebClient webClient(final WebClient.Builder builder) {
return builder.build();
}
#Bean
Function<Flux<Message<String>>, Flux<Message<String>>> functionStream(final WebClient webClient, final ObservationRegistry registry) {
return flux -> flux
.<Message<String>>handle((msg, sink) -> {
log.info("functionStream-1");
sink.next(msg);
})
.flatMap(msg -> webClient.get()
.uri("http://localhost:8080/test")
.exchangeToMono(httpResponse -> httpResponse.bodyToMono(String.class)
.map(httpBody -> MessageBuilder.withPayload(httpBody)
.copyHeaders(httpResponse.headers().asHttpHeaders())
.build())
.<Message<String>>handle((m, sink) -> {
log.info("functionStream-3");
sink.next(m);
})
)
)
.handle((msg, sink) -> {
log.info("functionStream-2");
sink.next(msg);
});
}
#Bean
Function<Flux<Message<String>>, Flux<Message<String>>> testStream(final ObservationRegistry registry) {
return flux -> flux
.publishOn(Schedulers.boundedElastic())
.<Message<String>>handle((msg, sink) -> {
log.info("testStream-1");
sink.next(msg);
})
.map(msg -> MessageBuilder
.withPayload(msg.getPayload())
.copyHeaders(msg.getHeaders())
.build());
}
#Bean
RouterFunction<ServerResponse> router(final ObservationRegistry registry) {
return route()
.GET("/test", r -> ServerResponse.ok().body(Mono.deferContextual(contextView -> {
try (final var scope = ContextSnapshot.setThreadLocalsFrom(contextView, ObservationThreadLocalAccessor.KEY)) {
log.info("GET /test");
}
return Mono.just("answer");
}), String.class))
.build();
}
With this code I have output:
2023-02-16T17:06:22.111 INFO [63ee385de15f1061dea076eb06b0d1e0,39a60588a695a702] 220348 --- [container-0-C-1] com.example.demo.TestApplication : functionStream-1
2023-02-16T17:06:22.166 WARN [63ee385de15f1061dea076eb06b0d1e0,39a60588a695a702] 220348 --- [container-0-C-1] i.m.o.c.ObservationThreadLocalAccessor : Scope from ObservationThreadLocalAccessor [null] is not the same as the one from ObservationRegistry [io.micrometer.observation.SimpleObservation$SimpleScope#523fe6a9]. You must have created additional scopes and forgotten to close them. Will close both of them
2023-02-16T17:06:22.170 WARN [63ee385de15f1061dea076eb06b0d1e0,de5d233d531b10f7] 220348 --- [container-0-C-1] i.m.o.c.ObservationThreadLocalAccessor : Scope from ObservationThreadLocalAccessor [null] is not the same as the one from ObservationRegistry [io.micrometer.observation.SimpleObservation$SimpleScope#545339d8]. You must have created additional scopes and forgotten to close them. Will close both of them
2023-02-16T17:06:22.187 WARN [63ee385de15f1061dea076eb06b0d1e0,de5d233d531b10f7] 220348 --- [container-0-C-1] i.m.o.c.ObservationThreadLocalAccessor : Scope from ObservationThreadLocalAccessor [null] is not the same as the one from ObservationRegistry [io.micrometer.observation.SimpleObservation$SimpleScope#44400bcc]. You must have created additional scopes and forgotten to close them. Will close both of them
2023-02-16T17:06:22.361 INFO [63ee385de15f1061dea076eb06b0d1e0,908f48f8485a4277] 220348 --- [ctor-http-nio-4] com.example.demo.TestApplication : GET /test
2023-02-16T17:06:22.407 INFO [,] 220348 --- [ctor-http-nio-3] com.example.demo.TestApplication : functionStream-3
2023-02-16T17:06:22.409 INFO [,] 220348 --- [ctor-http-nio-3] com.example.demo.TestApplication : functionStream-2
2023-02-16T17:06:22.448 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,dd1b0fd86a6c39ca] 220348 --- [ctor-http-nio-3] o.a.k.clients.admin.AdminClientConfig : AdminClientConfig values:
2023-02-16T17:06:22.456 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,dd1b0fd86a6c39ca] 220348 --- [ctor-http-nio-3] o.a.kafka.common.utils.AppInfoParser : Kafka version: 3.3.2
2023-02-16T17:06:22.457 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,dd1b0fd86a6c39ca] 220348 --- [ctor-http-nio-3] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: b66af662e61082cb
2023-02-16T17:06:22.457 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,dd1b0fd86a6c39ca] 220348 --- [ctor-http-nio-3] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1676556382456
2023-02-16T17:06:22.477 INFO [,] 220348 --- [| adminclient-6] o.a.kafka.common.utils.AppInfoParser : App info kafka.admin.client for adminclient-6 unregistered
2023-02-16T17:06:22.481 INFO [,] 220348 --- [| adminclient-6] o.apache.kafka.common.metrics.Metrics : Metrics scheduler closed
2023-02-16T17:06:22.481 INFO [,] 220348 --- [| adminclient-6] o.apache.kafka.common.metrics.Metrics : Closing reporter org.apache.kafka.common.metrics.JmxReporter
2023-02-16T17:06:22.481 INFO [,] 220348 --- [| adminclient-6] o.apache.kafka.common.metrics.Metrics : Metrics reporters closed
2023-02-16T17:06:22.512 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,b5babc6bef4e30ca] 220348 --- [oundedElastic-1] com.example.demo.TestApplication : testStream-1
2023-02-16T17:06:22.539 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,30126c50752d5928] 220348 --- [oundedElastic-1] o.a.k.clients.admin.AdminClientConfig : AdminClientConfig values:
2023-02-16T17:06:22.543 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,30126c50752d5928] 220348 --- [oundedElastic-1] o.a.kafka.common.utils.AppInfoParser : Kafka version: 3.3.2
2023-02-16T17:06:22.544 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,30126c50752d5928] 220348 --- [oundedElastic-1] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: b66af662e61082cb
2023-02-16T17:06:22.544 INFO [63ee385eda64dcebdd1b0fd86a6c39ca,30126c50752d5928] 220348 --- [oundedElastic-1] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1676556382543
Without http call I have output:
2023-02-16T17:03:09.518 INFO [63ee379d924e5645fc1d9e27b8135b48,9ad408700a3b5684] 204228 --- [container-0-C-1] com.example.demo.TestApplication : functionStream-1
2023-02-16T17:03:09.518 INFO [63ee379d924e5645fc1d9e27b8135b48,9ad408700a3b5684] 204228 --- [container-0-C-1] com.example.demo.TestApplication : functionStream-2
2023-02-16T17:03:09.615 INFO [63ee379d924e5645fc1d9e27b8135b48,3d4c6bd14a3ca4b6] 204228 --- [container-0-C-1] o.a.k.clients.admin.AdminClientConfig : AdminClientConfig values:
2023-02-16T17:03:09.629 INFO [63ee379d924e5645fc1d9e27b8135b48,3d4c6bd14a3ca4b6] 204228 --- [container-0-C-1] o.a.kafka.common.utils.AppInfoParser : Kafka version: 3.3.2
2023-02-16T17:03:09.629 INFO [63ee379d924e5645fc1d9e27b8135b48,3d4c6bd14a3ca4b6] 204228 --- [container-0-C-1] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: b66af662e61082cb
2023-02-16T17:03:09.629 INFO [63ee379d924e5645fc1d9e27b8135b48,3d4c6bd14a3ca4b6] 204228 --- [container-0-C-1] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1676556189628
2023-02-16T17:03:09.691 INFO [,] 204228 --- [| adminclient-6] o.a.kafka.common.utils.AppInfoParser : App info kafka.admin.client for adminclient-6 unregistered
2023-02-16T17:03:09.693 INFO [,] 204228 --- [| adminclient-6] o.apache.kafka.common.metrics.Metrics : Metrics scheduler closed
2023-02-16T17:03:09.693 INFO [,] 204228 --- [| adminclient-6] o.apache.kafka.common.metrics.Metrics : Closing reporter org.apache.kafka.common.metrics.JmxReporter
2023-02-16T17:03:09.693 INFO [,] 204228 --- [| adminclient-6] o.apache.kafka.common.metrics.Metrics : Metrics reporters closed
2023-02-16T17:03:09.859 INFO [63ee379d924e5645fc1d9e27b8135b48,b92a1a59ffd32d80] 204228 --- [oundedElastic-1] com.example.demo.TestApplication : testStream-1
2023-02-16T17:03:09.868 INFO [63ee379d924e5645fc1d9e27b8135b48,db97f5eed98602f6] 204228 --- [oundedElastic-1] o.a.k.clients.admin.AdminClientConfig : AdminClientConfig values:
2023-02-16T17:03:09.874 INFO [63ee379d924e5645fc1d9e27b8135b48,db97f5eed98602f6] 204228 --- [oundedElastic-1] o.a.kafka.common.utils.AppInfoParser : Kafka version: 3.3.2
2023-02-16T17:03:09.874 INFO [63ee379d924e5645fc1d9e27b8135b48,db97f5eed98602f6] 204228 --- [oundedElastic-1] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: b66af662e61082cb
2023-02-16T17:03:09.874 INFO [63ee379d924e5645fc1d9e27b8135b48,db97f5eed98602f6] 204228 --- [oundedElastic-1] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1676556189874

Related

How to make different instances of consumers in the same consumer group consume different shards of the same kinesis stream?

I'm following the example given in spring-cloud-stream-samples with the following modifications.
application.yml
spring:
cloud:
stream:
instanceCount: 2
bindings:
produceOrder-out-0:
destination: test_stream
content-type: application/json
producer:
partitionCount: 2
partitionSelectorName: eventPartitionSelectorStrategy
partitionKeyExtractorName: eventPartitionKeyExtractorStrategy
processOrder-in-0:
group: eventConsumers
destination: test_stream
content-type: application/json
function:
definition: processOrder;produceOrder
ProducerConfiguration.java
package demo.config;
import demo.stream.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.binder.PartitionKeyExtractorStrategy;
import org.springframework.cloud.stream.binder.PartitionSelectorStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;
#Configuration
public class ProducerConfiguration {
private static Logger logger = LoggerFactory.getLogger(ProducerConfiguration.class);
#Bean
public PartitionSelectorStrategy eventPartitionSelectorStrategy() {
return new PartitionSelectorStrategy() {
#Override
public int selectPartition(Object key, int partitionCount) {
if(key instanceof Integer) {
int partition = (((Integer)key)%partitionCount + partitionCount)%partitionCount;
logger.info("key {} falls into partition {}" , key , partition);
return partition;
}
return 0;
}
};
}
#Bean
public PartitionKeyExtractorStrategy eventPartitionKeyExtractorStrategy() {
return new PartitionKeyExtractorStrategy() {
#Override
public Object extractKey(Message<?> message) {
if(message.getPayload() instanceof Event) {
return ((Event) message.getPayload()).hashCode();
} else {
return 0;
}
}
};
}
}
When I run two instances of this application by setting --spring.cloud.stream.instanceIndex=0 and --spring.cloud.stream.instanceIndex=1 I'm able to see the events getting produced. However, only one of the instance is consuming the records from both the partitions, the other instance is not consuming despite the producer creating partitioned records.
Logs seen in KinesisProducer
2022-09-04 00:17:22.628 INFO 34029 --- [ main] a.i.k.KinesisMessageDrivenChannelAdapter : started KinesisMessageDrivenChannelAdapter{shardOffsets=[KinesisShardOffset{iteratorType=LATEST, sequenceNumber='null', timestamp=null, stream='test_stream', shard='shardId-000000000000', reset=false}], consumerGroup='eventConsumers'}
2022-09-04 00:17:22.658 INFO 34029 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 64398 (http) with context path ''
2022-09-04 00:17:22.723 INFO 34029 --- [ main] demo.KinesisApplication : Started KinesisApplication in 18.487 seconds (JVM running for 19.192)
2022-09-04 00:17:23.938 INFO 34029 --- [esis-consumer-1] a.i.k.KinesisMessageDrivenChannelAdapter : The [ShardConsumer{shardOffset=KinesisShardOffset{iteratorType=LATEST, sequenceNumber='null', timestamp=null, stream='test_stream', shard='shardId-000000000000', reset=false}, state=NEW}] has been started.
2022-09-04 00:17:55.222 INFO 34029 --- [io-64398-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-09-04 00:17:55.222 INFO 34029 --- [io-64398-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-09-04 00:17:55.224 INFO 34029 --- [io-64398-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2022-09-04 00:17:55.598 INFO 34029 --- [io-64398-exec-1] demo.stream.OrdersSource : Event sent: Event [id=null, subject=Order [id=5fbaca2f-d947-423d-a1f1-b1c9c268d2d0, name=pen], type=ORDER, originator=KinesisProducer]
2022-09-04 00:17:56.337 INFO 34029 --- [ask-scheduler-3] demo.config.ProducerConfiguration : key 1397835167 falls into partition 1
2022-09-04 00:18:02.047 INFO 34029 --- [io-64398-exec-2] demo.stream.OrdersSource : Event sent: Event [id=null, subject=Order [id=83021259-89b5-4451-a0ec-da3152d37a58, name=pen], type=ORDER, originator=KinesisProducer]
2022-09-04 00:18:02.361 INFO 34029 --- [ask-scheduler-3] demo.config.ProducerConfiguration : key 147530256 falls into partition 0
Logs seen in KinesisConsumer
2022-09-04 00:17:28.050 INFO 34058 --- [ main] a.i.k.KinesisMessageDrivenChannelAdapter : started KinesisMessageDrivenChannelAdapter{shardOffsets=[KinesisShardOffset{iteratorType=LATEST, sequenceNumber='null', timestamp=null, stream='test_stream', shard='shardId-000000000001', reset=false}], consumerGroup='eventConsumers'}
2022-09-04 00:17:28.076 INFO 34058 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 64399 (http) with context path ''
2022-09-04 00:17:28.116 INFO 34058 --- [ main] demo.KinesisApplication : Started KinesisApplication in 18.566 seconds (JVM running for 19.839)
2022-09-04 00:17:29.365 INFO 34058 --- [esis-consumer-1] a.i.k.KinesisMessageDrivenChannelAdapter : The [ShardConsumer{shardOffset=KinesisShardOffset{iteratorType=AFTER_SEQUENCE_NUMBER, sequenceNumber='49632927200161141377996226513172299243826807332967284754', timestamp=null, stream='test_stream', shard='shardId-000000000001', reset=false}, state=NEW}] has been started.
2022-09-04 00:17:57.346 INFO 34058 --- [esis-consumer-1] demo.stream.OrderStreamConfiguration : An order has been placed from this service Event [id=null, subject=Order [id=5fbaca2f-d947-423d-a1f1-b1c9c268d2d0, name=pen], type=ORDER, originator=KinesisProducer]
2022-09-04 00:18:04.384 INFO 34058 --- [esis-consumer-1] demo.stream.OrderStreamConfiguration : An order has been placed from this service Event [id=null, subject=Order [id=83021259-89b5-4451-a0ec-da3152d37a58, name=pen], type=ORDER, originator=KinesisProducer]
spring-cloud-stream-binder-kinesis version : 2.2.0
I have these following questions:
For Static shard distribution within a single consumer group, is there any other parameter that needs to be configured that I have missed?
Do I need to specify the DynamoDB Checkpoint properties only for dynamic shard distribution?
EDIT
I have added the DEBUG logs seen in KinesisProducer below:
2022-09-07 08:30:38.120 INFO 4993 --- [io-64398-exec-1] demo.stream.OrdersSource : Event sent: Event [id=null, subject=Order [id=b3927132-a80d-481e-a219-dbd0c0c7d124, name=pen], type=ORDER, originator=KinesisProducer]
2022-09-07 08:30:38.806 INFO 4993 --- [ask-scheduler-3] demo.config.ProducerConfiguration : key 1842629003 falls into partition 1
2022-09-07 08:30:38.812 DEBUG 4993 --- [ask-scheduler-3] o.s.c.s.m.DirectWithAttributesChannel : preSend on channel 'bean 'produceOrder-out-0'', message: GenericMessage [payload=byte[126], headers={scst_partition=1, id=9cb8ec58-4a9e-7b6f-4263-c9d4d1eec906, contentType=application/json, timestamp=1662519638809}]
2022-09-07 08:30:38.813 DEBUG 4993 --- [ask-scheduler-3] tractMessageChannelBinder$SendingHandler : org.springframework.cloud.stream.binder.AbstractMessageChannelBinder$SendingHandler#63811d15 received message: GenericMessage [payload=byte[126], headers={scst_partition=1, scst_partitionOverride=0, id=731f444b-d3df-a51a-33de-8adf78e1e746, contentType=application/json, timestamp=1662519638813}]
2022-09-07 08:30:38.832 DEBUG 4993 --- [ask-scheduler-3] o.s.c.s.m.DirectWithAttributesChannel : postSend (sent=true) on channel 'bean 'produceOrder-out-0'', message: GenericMessage [payload=byte[126], headers={scst_partition=1, scst_partitionOverride=0, id=731f444b-d3df-a51a-33de-8adf78e1e746, contentType=application/json, timestamp=1662519638813}]
2022-09-07 08:35:51.153 INFO 4993 --- [io-64398-exec-2] demo.stream.OrdersSource : Event sent: Event [id=null, subject=Order [id=6a5b3084-11dc-4080-a80e-61cc73315139, name=pen], type=ORDER, originator=KinesisProducer]
2022-09-07 08:35:51.915 INFO 4993 --- [ask-scheduler-5] demo.config.ProducerConfiguration : key 1525662264 falls into partition 0
2022-09-07 08:35:51.916 DEBUG 4993 --- [ask-scheduler-5] o.s.c.s.m.DirectWithAttributesChannel : preSend on channel 'bean 'produceOrder-out-0'', message: GenericMessage [payload=byte[126], headers={scst_partition=0, id=115c5421-00f2-286d-de02-0020e9322a17, contentType=application/json, timestamp=1662519951916}]
2022-09-07 08:35:51.916 DEBUG 4993 --- [ask-scheduler-5] tractMessageChannelBinder$SendingHandler : org.springframework.cloud.stream.binder.AbstractMessageChannelBinder$SendingHandler#63811d15 received message: GenericMessage [payload=byte[126], headers={scst_partition=0, scst_partitionOverride=0, id=145be7e8-381f-af73-e430-9cb645ff785f, contentType=application/json, timestamp=1662519951916}]
2022-09-07 08:35:51.917 DEBUG 4993 --- [ask-scheduler-5] o.s.c.s.m.DirectWithAttributesChannel : postSend (sent=true) on channel 'bean 'produceOrder-out-0'', message: GenericMessage [payload=byte[126], headers={scst_partition=0, scst_partitionOverride=0, id=145be7e8-381f-af73-e430-9cb645ff785f, contentType=application/json, timestamp=1662519951916}]

faced 'Spring Security & whitelabel Error 404' at the very first step

I just started making
Springboot starter project with gradle
first of all, i can't understand why i see security log-in page even when i set config permitAll
and secondly, i see 404 error after i log-in correctly
this is my SecurityConfig
package config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
#Configuration
#EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
// TODO Auto-generated method stub
//super.configure(http);
http.authorizeRequests()
.anyRequest().permitAll();
}
}
this is the controller
package notice;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class ApiNoticeController {
#GetMapping("/api/notice")
public String noticeSting() {
return "notice";
}
}
dependencies
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'org.springframework.security:spring-security-test'
}
console
2022-03-23 18:50:34.733 INFO 27256 --- [ main] com.example.demo.PracticeApplication : Starting PracticeApplication using Java 17.0.1 on DESKTOP-JBB51IM with PID 27256 (C:\Users\user1\Desktop\CRUD\practice\bin\main started by user1 in C:\Users\user1\Desktop\CRUD\practice)
2022-03-23 18:50:34.740 INFO 27256 --- [ main] com.example.demo.PracticeApplication : No active profile set, falling back to 1 default profile: "default"
2022-03-23 18:50:36.429 INFO 27256 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-03-23 18:50:36.453 INFO 27256 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8 ms. Found 0 JPA repository interfaces.
2022-03-23 18:50:37.521 INFO 27256 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-03-23 18:50:37.538 INFO 27256 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-03-23 18:50:37.538 INFO 27256 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-03-23 18:50:37.773 INFO 27256 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-03-23 18:50:37.774 INFO 27256 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2922 ms
2022-03-23 18:50:38.067 INFO 27256 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-03-23 18:50:38.415 INFO 27256 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-03-23 18:50:38.508 INFO 27256 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-03-23 18:50:38.614 INFO 27256 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.5.Final
2022-03-23 18:50:39.009 INFO 27256 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-03-23 18:50:39.252 INFO 27256 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-03-23 18:50:39.781 INFO 27256 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-03-23 18:50:39.801 INFO 27256 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-03-23 18:50:39.866 WARN 27256 --- [ 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-03-23 18:50:40.609 INFO 27256 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: ****
2022-03-23 18:50:40.934 INFO 27256 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will not secure any request
2022-03-23 18:50:41.124 INFO 27256 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-03-23 18:50:41.145 INFO 27256 --- [ main] com.example.demo.PracticeApplication : Started PracticeApplication in 7.185 seconds (JVM running for 9.471)
2022-03-23 18:50:48.680 INFO 27256 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-23 18:50:48.680 INFO 27256 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-03-23 18:50:48.681 INFO 27256 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2022-03-23 18:50:49.157 WARN 27256 --- [nio-8080-exec-1] o.a.c.util.SessionIdGeneratorBase : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [397] milliseconds.
it worked well at first, returning URL "http://localhost:8080/api/notice" & String "notice"
but suddenly not working...
What I know and saw is that I used #RestController so i don't need html view resolver...
i also tried with configuration -
// super.configure(http);
super.configure(http);
both...didn't work
Sorry it was a stupid mistake.... as you can see in the package name, i set the package path wrong. thanks everybody for reading

Create Spring Cloud Data Flow Processor using Gradle and Kotlin

I'm trying to build a Kotlin Processor based on Spring Cloud Stream 3.1 using Kotlin Lambda.
I'm deploying this processor into a stream using Spring Cloud Data Flow but it is marked as failed.
If I cat the error log I have the following error : IllegalArgumentException: Type must be one of Supplier, Function or Consumer
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'functionBindingRegistrar' defined in class path resource [org/springframework/cloud/stream/function/FunctionConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Type must be one of Supplier, Function or Consumer
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788) ~[spring-beans-5.3.2.jar!/:5.3.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.2.jar!/:5.3.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.2.jar!/:5.3.2]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.2.jar!/:5.3.2]
Here is my code :
#SpringBootApplication
class TransformerUppercaseApplication{
#Bean
fun transform(): (String) -> String {
return { "This is my uppercase".plus(it.toUpperCase()) }
}
}
fun main(args: Array<String>) {
runApplication<TransformerUppercaseApplication>(*args)
}
I've tried specifying the function name into my application.yml but no success:
spring:
cloud:
stream:
function:
definition: transform
Here is my build.gradle.kts :
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`maven-publish`
id("org.springframework.boot") version "2.4.1"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
kotlin("jvm") version "1.4.21"
kotlin("plugin.spring") version "1.4.21"
}
group = "com.company"
version = "0.0.11"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
maven { url = uri("https://repo.spring.io/milestone") }
}
extra["springCloudVersion"] = "2020.0.0"
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.cloud:spring-cloud-starter-stream-kafka")
implementation("org.springframework.cloud:spring-cloud-function-kotlin")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}
configurations {
val elements = listOf(apiElements, runtimeElements)
elements.forEach { element ->
element.get().outgoing.artifacts.removeIf { it -> it.buildDependencies.getDependencies(null).contains(tasks.jar.get())}
element.get().outgoing.artifact(tasks.bootJar.get())
}
}
Edit : I can get away from the error by using the java Function class instead of kotlin lambda :
#Bean
fun transform(): Function<String, String> = Function {
it.toUpperCase()
}
But for now a new problem appear, the processor is unable to bind to kafka topic, it's shown as anonymous and the processor kepp status deploying. I got this in the processor log (I've tried in a java sample too) :
2021-01-19 08:13:27.674 INFO 107 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka version: 2.6.0
2021-01-19 08:13:27.674 INFO 107 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: 62abe01bee039651
2021-01-19 08:13:27.674 INFO 107 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1611044007674
2021-01-19 08:13:27.676 INFO 107 --- [ main] o.a.k.clients.consumer.KafkaConsumer : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Subscribed to topic(s): transform-in-0
2021-01-19 08:13:27.677 INFO 107 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService
2021-01-19 08:13:27.702 INFO 107 --- [ main] s.i.k.i.KafkaMessageDrivenChannelAdapter : started org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter#24fabd0f
2021-01-19 08:13:27.715 INFO 107 --- [ main] c.e.t.TransformerUppercaseApplicationKt : Started TransformerUppercaseApplicationKt in 7.538 seconds (JVM running for 8.374)
2021-01-19 08:13:27.729 INFO 107 --- [container-0-C-1] org.apache.kafka.clients.Metadata : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Cluster ID: gN63F8OzRwaEeKElBfkmjw
2021-01-19 08:13:28.827 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Discovered group coordinator kafka-broker:9092 (id: 2147482646 rack: null)
2021-01-19 08:13:28.833 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] (Re-)joining group
2021-01-19 08:13:28.866 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Join group failed with org.apache.kafka.common.errors.MemberIdRequiredException: The group member needs to have a valid member id before actually entering a consumer group.
2021-01-19 08:13:28.866 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] (Re-)joining group
2021-01-19 08:13:31.890 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Finished assignment for group at generation 1: {consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2-61cd1b1a-6485-4bc8-83e8-003bc22db7e1=Assignment(partitions=[transform-in-0-0])}
2021-01-19 08:13:31.935 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Successfully joined group with generation 1
2021-01-19 08:13:31.936 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Notifying assignor about the new Assignment(partitions=[transform-in-0-0])
2021-01-19 08:13:31.939 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Adding newly assigned partitions: transform-in-0-0
2021-01-19 08:13:31.950 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Found no committed offset for partition transform-in-0-0
2021-01-19 08:13:31.963 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Found no committed offset for partition transform-in-0-0
2021-01-19 08:13:31.977 INFO 107 --- [container-0-C-1] o.a.k.c.c.internals.SubscriptionState : [Consumer clientId=consumer-anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3-2, groupId=anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3] Resetting offset for partition transform-in-0-0 to offset 0.
2021-01-19 08:13:32.007 INFO 107 --- [container-0-C-1] o.s.c.s.b.k.KafkaMessageChannelBinder$2 : anonymous.899f643d-9e17-4354-824c-96e77ec4c5b3: partitions assigned: [transform-in-0-0]
Please compare your sample with the Kotlin example that we have in the Microsite.
Perhaps even repeat the example as-is and get it working in your environment to get comfortable with it also. You should be able to use your app in the same manner after the fact.
I managed to get it work !
The Kotlin lambda detection problem is a problem with the 2020.0.0 release. it works with the Hoxton.SR9
The anonymous consumer problems (in the Edit) was resolved by adding these two lines in the application.properies
spring.cloud.stream.function.bindings.transform-in-0=input
spring.cloud.stream.function.bindings.transform-out-0=output

Hibernate - Dialect configured but still getting error

I'm updating a JHipster microservice and found some issues when running the app in production environment. The application crashes with a strange Hibernate error:
2020-10-22 10:59:12.755 INFO 1 --- [ main] com.hazelcast.core.LifecycleService : [172.18.0.3]:5701 [dev] [3.12.7] [172.18.0.3]:5701 is STARTED
2020-10-22 10:59:13.066 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : Driver class org.postgresql.Driver found in Thread context class loader jdk.internal.loader.ClassLoaders$AppClassLoader#4ae3c1cd
2020-10-22 10:59:13.868 INFO 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1603364353868, current=UP, previous=STARTING]
2020-10-22 10:59:13.946 INFO 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_MISCELLANEOUS/miscellaneous:2b1983b040c376288a15e1a536a4f8f9: registering service...
2020-10-22 10:59:14.182 INFO 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_MISCELLANEOUS/miscellaneous:2b1983b040c376288a15e1a536a4f8f9 - registration status: 204
2020-10-22 10:59:14.257 INFO 1 --- [ main] t.h.e.m.config.WebConfigurer : Web application configuration, using profiles: prod
2020-10-22 10:59:14.258 INFO 1 --- [ main] t.h.e.m.config.WebConfigurer : Web application fully configured
2020-10-22 10:59:14.961 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : Hikari - configuration:
2020-10-22 10:59:14.969 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : allowPoolSuspension.............false
2020-10-22 10:59:14.969 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : autoCommit......................false
2020-10-22 10:59:14.969 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : catalog.........................none
2020-10-22 10:59:14.970 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : connectionInitSql...............none
2020-10-22 10:59:14.970 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : connectionTestQuery.............none
2020-10-22 10:59:14.971 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : connectionTimeout...............30000
2020-10-22 10:59:14.971 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : dataSource......................none
2020-10-22 10:59:14.971 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : dataSourceClassName.............none
2020-10-22 10:59:14.972 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : dataSourceJNDI..................none
2020-10-22 10:59:15.042 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : dataSourceProperties............{password=<masked>}
2020-10-22 10:59:15.043 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : driverClassName................."org.postgresql.Driver"
2020-10-22 10:59:15.043 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : exceptionOverrideClassName......none
2020-10-22 10:59:15.044 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : healthCheckProperties...........{}
2020-10-22 10:59:15.045 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : healthCheckRegistry.............none
2020-10-22 10:59:15.045 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : idleTimeout.....................600000
2020-10-22 10:59:15.047 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : initializationFailTimeout.......1
2020-10-22 10:59:15.048 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : isolateInternalQueries..........false
2020-10-22 10:59:15.049 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : jdbcUrl.........................jdbc:postgresql://postgresql:5432/miscellaneous?socketTimeout=30
2020-10-22 10:59:15.050 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : leakDetectionThreshold..........15000
2020-10-22 10:59:15.050 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : maxLifetime.....................1800000
2020-10-22 10:59:15.050 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : maximumPoolSize.................5
2020-10-22 10:59:15.051 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : metricRegistry..................none
2020-10-22 10:59:15.051 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : metricsTrackerFactory...........none
2020-10-22 10:59:15.051 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : minimumIdle.....................5
2020-10-22 10:59:15.054 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : password........................<masked>
2020-10-22 10:59:15.055 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : poolName........................"Hikari"
2020-10-22 10:59:15.056 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : readOnly........................false
2020-10-22 10:59:15.057 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : registerMbeans..................false
2020-10-22 10:59:15.059 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : scheduledExecutor...............none
2020-10-22 10:59:15.059 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : schema..........................none
2020-10-22 10:59:15.059 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : threadFactory...................internal
2020-10-22 10:59:15.060 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : transactionIsolation............default
2020-10-22 10:59:15.061 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : username........................"teste"
2020-10-22 10:59:15.064 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : validationTimeout...............5000
2020-10-22 10:59:15.065 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : Hikari - Starting...
2020-10-22 10:59:15.445 DEBUG 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : Hikari - Added connection org.postgresql.jdbc.PgConnection#47d6a31a
2020-10-22 10:59:15.450 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : Hikari - Start completed.
2020-10-22 10:59:15.550 DEBUG 1 --- [ari housekeeper] com.zaxxer.hikari.pool.HikariPool : Hikari - Pool stats (total=1, active=1, idle=0, waiting=0)
2020-10-22 10:59:15.566 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : Hikari - Added connection org.postgresql.jdbc.PgConnection#c2d5356
2020-10-22 10:59:15.573 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : Hikari - Added connection org.postgresql.jdbc.PgConnection#2eaaca3
2020-10-22 10:59:15.643 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : Hikari - Added connection org.postgresql.jdbc.PgConnection#6d53826
2020-10-22 10:59:15.654 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : Hikari - Added connection org.postgresql.jdbc.PgConnection#43d7a698
2020-10-22 10:59:15.659 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : Hikari - After adding stats (total=5, active=1, idle=4, waiting=0)
2020-10-22 10:59:28.156 WARN 1 --- [scoveryClient-0] c.netflix.discovery.TimedSupervisorTask : task supervisor timed out
java.util.concurrent.TimeoutException: null
at java.base/java.util.concurrent.FutureTask.get(Unknown Source)
at com.netflix.discovery.TimedSupervisorTask.run(TimedSupervisorTask.java:68)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
2020-10-22 10:59:30.453 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : Hikari - Shutdown initiated...
2020-10-22 10:59:30.454 DEBUG 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : Hikari - Before shutdown stats (total=5, active=0, idle=5, waiting=0)
2020-10-22 10:59:30.465 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : Hikari - Closing connection org.postgresql.jdbc.PgConnection#47d6a31a: (connection evicted)
2020-10-22 10:59:30.471 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : Hikari - Closing connection org.postgresql.jdbc.PgConnection#c2d5356: (connection evicted)
2020-10-22 10:59:30.544 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : Hikari - Closing connection org.postgresql.jdbc.PgConnection#2eaaca3: (connection evicted)
2020-10-22 10:59:30.545 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : Hikari - Closing connection org.postgresql.jdbc.PgConnection#6d53826: (connection evicted)
2020-10-22 10:59:30.548 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : Hikari - Closing connection org.postgresql.jdbc.PgConnection#43d7a698: (connection evicted)
2020-10-22 10:59:30.564 DEBUG 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : Hikari - After shutdown stats (total=0, active=0, idle=0, waiting=0)
2020-10-22 10:59:30.564 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : Hikari - Shutdown completed.
2020-10-22 10:59:30.565 WARN 1 --- [ main] i.g.j.c.liquibase.AsyncSpringLiquibase : Warning, Liquibase took more than 5 seconds to start up!
2020-10-22 10:59:31.050 DEBUG 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : PersistenceUnitInfo [
name: default
persistence provider classname: null
classloader: jdk.internal.loader.ClassLoaders$AppClassLoader#4ae3c1cd
excludeUnlistedClasses: true
JTA datasource: null
Non JTA datasource: HikariDataSource (Hikari)
Transaction type: RESOURCE_LOCAL
PU root URL: file:/app/libs/commons-microservice-1.1.0.jar
Shared Cache Mode: UNSPECIFIED
Validation Mode: AUTO
Jar files URLs []
Managed classes names [
tech.h2r.ecommerce.miscellaneous.domain.AbstractAuditingEntity
tech.h2r.ecommerce.miscellaneous.domain.Banner
tech.h2r.ecommerce.miscellaneous.domain.CustomPage
tech.h2r.ecommerce.miscellaneous.domain.DirectMail
tech.h2r.ecommerce.miscellaneous.domain.PersistentAuditEvent
tech.h2r.ecommerce.miscellaneous.domain.Theme
tech.h2r.commons.microservice.domain.ConsumedMessage
tech.h2r.commons.microservice.domain.ProducedMessage
tech.h2r.commons.domain.Config]
Mapping files names []
Properties []
2020-10-22 10:59:31.064 DEBUG 1 --- [ main] o.h.i.internal.IntegratorServiceImpl : Adding Integrator [org.hibernate.cfg.beanvalidation.BeanValidationIntegrator].
2020-10-22 10:59:31.066 DEBUG 1 --- [ main] o.h.i.internal.IntegratorServiceImpl : Adding Integrator [org.hibernate.secure.spi.JaccIntegrator].
2020-10-22 10:59:31.068 DEBUG 1 --- [ main] o.h.i.internal.IntegratorServiceImpl : Adding Integrator [org.hibernate.cache.internal.CollectionCacheInvalidator].
2020-10-22 10:59:31.270 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.15.Final
2020-10-22 10:59:31.343 DEBUG 1 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-10-22 10:59:31.851 DEBUG 1 --- [ main] o.hibernate.service.spi.ServiceBinding : Overriding existing service binding [org.hibernate.secure.spi.JaccService]
2020-10-22 10:59:31.867 DEBUG 1 --- [ main] o.h.c.internal.RegionFactoryInitiator : Cannot default RegionFactory based on registered strategies as `[]` RegionFactory strategies were registered
2020-10-22 10:59:31.868 DEBUG 1 --- [ main] o.h.c.internal.RegionFactoryInitiator : Cache region factory : org.hibernate.cache.internal.NoCachingRegionFactory
2020-10-22 10:59:31.960 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-10-22 10:59:32.769 DEBUG 1 --- [ main] o.h.boot.internal.BootstrapContextImpl : Injecting JPA temp ClassLoader [org.springframework.instrument.classloading.SimpleThrowawayClassLoader#20852557] into BootstrapContext; was [null]
2020-10-22 10:59:32.770 DEBUG 1 --- [ main] o.h.boot.internal.ClassLoaderAccessImpl : ClassLoaderAccessImpl#injectTempClassLoader(org.springframework.instrument.classloading.SimpleThrowawayClassLoader#20852557) [was null]
2020-10-22 10:59:32.771 DEBUG 1 --- [ main] o.h.boot.internal.BootstrapContextImpl : Injecting ScanEnvironment [org.hibernate.jpa.boot.internal.StandardJpaScanEnvironmentImpl#41ca7df9] into BootstrapContext; was [null]
2020-10-22 10:59:32.842 DEBUG 1 --- [ main] o.h.boot.internal.BootstrapContextImpl : Injecting ScanOptions [org.hibernate.boot.archive.scan.internal.StandardScanOptions#4f0908de] into BootstrapContext; was [org.hibernate.boot.archive.scan.internal.StandardScanOptions#19469022]
2020-10-22 10:59:33.153 DEBUG 1 --- [ main] o.h.boot.internal.BootstrapContextImpl : Injecting JPA temp ClassLoader [null] into BootstrapContext; was [org.springframework.instrument.classloading.SimpleThrowawayClassLoader#20852557]
2020-10-22 10:59:33.160 DEBUG 1 --- [ main] o.h.boot.internal.ClassLoaderAccessImpl : ClassLoaderAccessImpl#injectTempClassLoader(null) [was org.springframework.instrument.classloading.SimpleThrowawayClassLoader#20852557]
2020-10-22 10:59:33.243 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [uuid2] -> [org.hibernate.id.UUIDGenerator]
2020-10-22 10:59:33.243 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [guid] -> [org.hibernate.id.GUIDGenerator]
2020-10-22 10:59:33.244 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [uuid] -> [org.hibernate.id.UUIDHexGenerator]
2020-10-22 10:59:33.245 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [uuid.hex] -> [org.hibernate.id.UUIDHexGenerator]
2020-10-22 10:59:33.245 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [assigned] -> [org.hibernate.id.Assigned]
2020-10-22 10:59:33.247 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [identity] -> [org.hibernate.id.IdentityGenerator]
2020-10-22 10:59:33.249 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [select] -> [org.hibernate.id.SelectGenerator]
2020-10-22 10:59:33.251 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [sequence] -> [org.hibernate.id.enhanced.SequenceStyleGenerator]
2020-10-22 10:59:33.253 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [seqhilo] -> [org.hibernate.id.SequenceHiLoGenerator]
2020-10-22 10:59:33.254 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [increment] -> [org.hibernate.id.IncrementGenerator]
2020-10-22 10:59:33.255 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [foreign] -> [org.hibernate.id.ForeignGenerator]
2020-10-22 10:59:33.256 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [sequence-identity] -> [org.hibernate.id.SequenceIdentityGenerator]
2020-10-22 10:59:33.256 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [enhanced-sequence] -> [org.hibernate.id.enhanced.SequenceStyleGenerator]
2020-10-22 10:59:33.258 DEBUG 1 --- [ main] .i.f.i.DefaultIdentifierGeneratorFactory : Registering IdentifierGenerator strategy [enhanced-table] -> [org.hibernate.id.enhanced.TableGenerator]
2020-10-22 10:59:33.262 WARN 1 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : HikariDataSource HikariDataSource (Hikari) has been closed.
2020-10-22 10:59:33.266 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [tech/h2r/ecommerce/miscellaneous/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2020-10-22 10:59:33.365 INFO 1 --- [ main] com.hazelcast.core.LifecycleService : [172.18.0.3]:5701 [dev] [3.12.7] [172.18.0.3]:5701 is SHUTTING_DOWN
2020-10-22 10:59:33.449 INFO 1 --- [ main] com.hazelcast.instance.Node : [172.18.0.3]:5701 [dev] [3.12.7] Shutting down connection manager...
2020-10-22 10:59:33.457 INFO 1 --- [ main] com.hazelcast.instance.Node : [172.18.0.3]:5701 [dev] [3.12.7] Shutting down node engine...
2020-10-22 10:59:33.547 INFO 1 --- [ main] com.hazelcast.instance.NodeExtension : [172.18.0.3]:5701 [dev] [3.12.7] Destroying node NodeExtension.
2020-10-22 10:59:33.548 INFO 1 --- [ main] com.hazelcast.instance.Node : [172.18.0.3]:5701 [dev] [3.12.7] Hazelcast Shutdown is completed in 101 ms.
2020-10-22 10:59:33.549 INFO 1 --- [ main] com.hazelcast.core.LifecycleService : [172.18.0.3]:5701 [dev] [3.12.7] [172.18.0.3]:5701 is SHUTDOWN
2020-10-22 10:59:33.550 INFO 1 --- [ main] t.h.e.m.config.CacheConfiguration : Closing Cache Manager
2020-10-22 10:59:33.554 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2020-10-22 10:59:36.557 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Unregistering ...
2020-10-22 10:59:36.666 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_MISCELLANEOUS/miscellaneous:2b1983b040c376288a15e1a536a4f8f9 - deregister status: 200
2020-10-22 10:59:36.744 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
2020-10-22 10:59:36.951 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [tech/h2r/ecommerce/miscellaneous/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
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:226)
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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
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 tech.h2r.ecommerce.miscellaneous.MiscellaneousApp.main(MiscellaneousApp.java:44)
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1214)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1245)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 14 common frames omitted
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
... 31 common frames omitted
The error says the problem is with dialect, but it is configured correctly:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://postgresql:5432/miscellaneous?socketTimeout=30
hikari:
poolName: Hikari
auto-commit: false
jpa:
database-platform: io.github.jhipster.domain.util.FixedPostgreSQL10Dialect
show-sql: false
open-in-view: false
properties:
hibernate.jdbc.time_zone: UTC
hibernate.id.new_generator_mappings: true
hibernate.connection.provider_disables_autocommit: true
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
hibernate.jdbc.batch_size: 25
hibernate.order_inserts: true
hibernate.order_updates: true
hibernate.query.fail_on_pagination_over_collection_fetch: true
hibernate.query.in_clause_parameter_padding: true
hibernate.cache.region.factory_class: com.hazelcast.hibernate.HazelcastCacheRegionFactory
hibernate.cache.use_minimal_puts: true
hibernate.cache.hazelcast.instance_name: miscellaneous
hibernate.cache.hazelcast.use_lite_member: true
hibernate:
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
What could be causing this problem?
Instead of use the injected jpaVendorAdapter in my EntityManager, I was creating it:
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, SchemaPerTenantConnectionProvider schemaPerTenantConnectionProvider, HeaderTenantIdentifierResolver headerTenantIdentifierResolver) {
...
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
simply using the injected bean solved this problem:
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, SchemaPerTenantConnectionProvider schemaPerTenantConnectionProvider, HeaderTenantIdentifierResolver headerTenantIdentifierResolver, JpaVendorAdapter jpaVendorAdapter) {
...
em.setJpaVendorAdapter(jpaVendorAdapter);
em.setJpaPropertyMap(properties);
return em;
}
Add the dialect to the properties under the name hibernate.dialect.

Why is my web service forbidding my connections when using .hasIpAddress()?

Defintieyl searched stackex for this already. Problems with hasIpAddress seem often unique.
I believe I understand the route of my reques to my server.
User -> Zuul -> My web service
http.authorizeRequests().antMatchers("/**").permitAll();
in my webservice, allows me to send requests and receive responses from localhost and my system's IP.
http.authorizeRequests().antMatchers("/**").hasIpAddress(10.10.1.24);
or
http.authorizeRequests().antMatchers("/**").hasIpAddress("127.0.0.1");
both fail.
When Zuul gives access to my web service... is it misreporting my request IP or something?
If my hasIpAddress() shouldnt be localhost, 127.0.0.1 or 10.10.1.24 then what else could it be?
I've shut down Zuul, Eureka and the ws and started them all up again.
I also did a maven clean.
2019-10-23 11:58:46.608 INFO 7468 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#27040a7b, org.springframework.security.web.context.SecurityContextPersistenceFilter#6d6a2d29, org.springframework.security.web.header.HeaderWriterFilter#3485fdae, org.springframework.security.web.authentication.logout.LogoutFilter#198a3831, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#2c7fb62d, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#20043371, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#ad82f08, org.springframework.security.web.session.SessionManagementFilter#2285c828, org.springframework.security.web.access.ExceptionTranslationFilter#6511c7f9, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#7e27dfef]
2019-10-23 11:58:46.618 WARN 7468 --- [ restartedMain] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-10-23 11:58:46.618 INFO 7468 --- [ restartedMain] 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.
2019-10-23 11:58:46.621 WARN 7468 --- [ restartedMain] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-10-23 11:58:46.621 INFO 7468 --- [ restartedMain] 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.
2019-10-23 11:58:46.731 INFO 7468 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-23 11:58:47.264 WARN 7468 --- [ restartedMain] ockingLoadBalancerClientRibbonWarnLogger : You already have RibbonLoadBalancerClient on your classpath. It will be used by default. As Spring Cloud Ribbon is in maintenance mode. We recommend switching to BlockingLoadBalancerClient instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
2019-10-23 11:58:47.365 INFO 7468 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 54293 (http) with context path ''
2019-10-23 11:58:47.366 INFO 7468 --- [ restartedMain] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 54293
2019-10-23 11:58:47.370 INFO 7468 --- [ restartedMain] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-10-23 11:58:47.392 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-10-23 11:58:47.491 INFO 7468 --- [ restartedMain] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2019-10-23 11:58:47.492 INFO 7468 --- [ restartedMain] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2019-10-23 11:58:47.570 INFO 7468 --- [ restartedMain] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2019-10-23 11:58:47.571 INFO 7468 --- [ restartedMain] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2019-10-23 11:58:47.690 INFO 7468 --- [ restartedMain] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2019-10-23 11:58:47.814 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2019-10-23 11:58:47.814 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2019-10-23 11:58:47.814 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2019-10-23 11:58:47.814 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Application is null : false
2019-10-23 11:58:47.815 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2019-10-23 11:58:47.815 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2019-10-23 11:58:47.815 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2019-10-23 11:58:47.890 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : The response status is 200
2019-10-23 11:58:47.892 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2019-10-23 11:58:47.894 INFO 7468 --- [ restartedMain] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2019-10-23 11:58:47.897 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1571842727896 with initial instances count: 0
2019-10-23 11:58:47.900 INFO 7468 --- [ restartedMain] o.s.c.n.e.s.EurekaServiceRegistry : Registering application USERS-WS with eureka with status UP
2019-10-23 11:58:47.900 INFO 7468 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1571842727900, current=UP, previous=STARTING]
2019-10-23 11:58:47.902 INFO 7468 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USERS-WS/users-ws:90ae4ec0932916bcd2b9155854f3a269: registering service...
2019-10-23 11:58:47.945 INFO 7468 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_USERS-WS/users-ws:90ae4ec0932916bcd2b9155854f3a269 - registration status: 204
2019-10-23 11:58:48.064 INFO 7468 --- [ restartedMain] c.p.p.a.u.PhotoAppApiUsersApplication : Started PhotoAppApiUsersApplication in 5.037 seconds (JVM running for 5.825)
2019-10-23 11:59:17.895 INFO 7468 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2019-10-23 11:59:17.895 INFO 7468 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2019-10-23 11:59:17.895 INFO 7468 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2019-10-23 11:59:17.896 INFO 7468 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Application is null : false
2019-10-23 11:59:17.896 INFO 7468 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2019-10-23 11:59:17.896 INFO 7468 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Application version is -1: false
2019-10-23 11:59:17.896 INFO 7468 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2019-10-23 11:59:17.959 INFO 7468 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : The response status is 200
Here is a working basic example using spring-boot 2.2.0.RELEASE with spring-boot-starter-security and spring-boot-starter-web
Works when accessing via http://localhost:8080/ip
#SpringBootApplication
public class SpringSecurityHasIpAddressApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSecurityHasIpAddressApplication.class, args);
}
}
#RestController
class HelloController {
#GetMapping("/hello")
public String hello() {
return "Hello World!";
}
#GetMapping("/ip")
public String ip(HttpServletRequest request) {
return request.getRemoteAddr();
}
#GetMapping("/secure")
public String secure(Principal principal,HttpServletRequest request) {
return principal.getName() + " with " + request.getRemoteAddr();
}
}
#Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(
authorizeRequests ->
authorizeRequests
.antMatchers("/hello").permitAll()
.antMatchers("/secure").authenticated()
.antMatchers("/ip").hasIpAddress("0:0:0:0:0:0:0:1") // localhost
.anyRequest().authenticated()
)
.formLogin();
}
}
You could access the /secure path, then you can see you're actually used IP-address.
0:0:0:0:0:0:0:1 is my localhost address so I can access /ip without authentication
By setting the log-level of org.springframework.security could also be very helpful.
application.properties
logging.level.org.springframework.security=debug
then you can see in logging something like:
2019-10-30 19:14:01.039 DEBUG 3692 --- [nio-8080-exec-6] o.s.s.w.a.i.FilterSecurityInterceptor : Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken#536ff536: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails#166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 7602343558C34E2576CD0D3E20EDCBEE; Granted Authorities: ROLE_ANONYMOUS
2019-10-30 19:14:01.040 DEBUG 3692 --- [nio-8080-exec-6] o.s.s.access.vote.AffirmativeBased : Voter: org.springframework.security.web.access.expression.WebExpressionVoter#7527e914, returned: -1
2019-10-30 19:14:01.041 DEBUG 3692 --- [nio-8080-exec-6] o.s.s.w.a.ExceptionTranslationFilter : Access is denied (user is anonymous); redirecting to authentication entry point
if you try via http://127.0.0.1/ip above solution will fail
then you can use
...
.antMatchers("/ip").hasIpAddress("127.0.0.1/32")
...
If you want to use a range of allowed IP-addresses then you could you use
...
.antMatchers("/access") // multiple IP matching
.access("hasIpAddress('192.168.0.1/16') or hasIpAddress('127.0.0.1/32')")
...
hasIpAddress(1.1.1.1) has always worked fine for me. you don't need the /32 but you can use it. it's actually the same IP with /32 on it but you really on need it if you're attempting to match a range of IPs in a subnet . My guess is you're getting the IP of Zuul and not localhost/127.0.0.1 and you're using embedded Tomcat without the <Valve className="org.apache.catalina.valves.RemoteIpValve" /> installed. Also, enable the access log for Tomcat to see what IP is hitting your service via the SPring Boot properties located at https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html - just search for tomcat

Resources