Spring Boot connecting to Pivotal Cloud Cache - spring

My project is using Spring Boot version 2.0.4-RELEASE.
We are deploying onto Pivotal Cloud Foundry and are using the Pivotal Cloud Cache service service which uses Apache Geode.
My code is up and running if I use the gemfire shell to create the Cloud Cache regions but I would like to create these regions from my code instead so that nothing is missed.
I have the following config class where I try to create a region
package com.mycompany.services.config;
import org.apache.geode.cache.ExpirationAction;
import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.RegionShortcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions;
import org.springframework.data.gemfire.config.annotation.EnablePdx;
#Configuration
#EnableCachingDefinedRegions
#EnablePdx()
public class Config {
#Bean
public PartitionedRegionFactoryBean<?, ?> createCacheRegion(GemFireCache gemfireCache) {
int expirationTime = 600;
String regionName = "cacheRegion";
PartitionedRegionFactoryBean<?, ?> newRegion = new PartitionedRegionFactoryBean<>();
newRegion.setCache(gemfireCache);
newRegion.setClose(false);
newRegion.setPersistent(true);
newRegion.setName(regionName);
ExpirationAttributes entryTimeToLive = new ExpirationAttributes(expirationTime, ExpirationAction.INVALIDATE);
newRegion.setEntryTimeToLive(entryTimeToLive);
newRegion.setShortcut(RegionShortcut.REPLICATE);
return newRegion;
}
}
However - when this code runs on Pivotal Cloud Foundry - I get the following error
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] 2018-11-08 17:46:09.795 ERROR 19 --- [ main] o.s.boot.SpringApplication : Application run failed
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dqsCacheRegion' defined in class path resource [com/mycompany/services/config/Config.class]: Invocation of init method failed; nested exception is java.lang.UnsupportedOperationException: operation is not supported on a client cache
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:740) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
2018-11-08T17:46:09.797+00:00 [APP/PROC/WEB/0] [OUT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar!/:2.0.4.RELEASE]
Can anyone offer any advise on what I need to do in order to create Pivotal Cloud Cache (Apache Geode) regions in my code as opposed to having to create them using the gemfire shell
Thank you
Damien

Client applications can't create regions on the servers, it's a task that should be executed by an operator with admin privileges, either through gfsh, individual cache.xml configuration files or the cluster configuration service. Allowing clients to arbitrarily create regions could be counter-productive and generate a huge amount of unused regions on your cluster and unnecessary noise and overhead, which is not recommended at all for production environments.
That said, Spring Data for Apache Geode/GemFire allows you to push your configuration to the Cluster from a client application automatically, which is useful in developments environments. I don't know if this is allowed by the Pivotal Cloud Cache internal policies and restrictions, you might want to check directly with Pivotal.
Hope this helps.
Cheers.

Related

How to accept custom HTTP error codes with the Micronaut client?

I'm setting up an HTTP client to an external API. That server has unusual status codes in case of errors in the payload sent (310 to 323).
However, Micronaut's HTTP client throws an IllegalArgumentException when trying to parse that response, due to its limited known list of status codes (https://github.com/micronaut-projects/micronaut-core/blob/master/http/src/main/java/io/micronaut/http/HttpStatus.java)
Moreover, when trying to write an async client with the JavaRx library, that error does NOT lead to an error being thrown immediately. It instead hangs for a few seconds and throws an ReadTimeoutException.
I tried Kotlin extensions to extend the HttpStatus enum, but failed. Not sure it is really possible in the way it is used.
Here is the client code:
#Context
#Requires(beans = [FooConfiguration::class])
class FooClient(
#Client("foo") private val httpClient: RxHttpClient,
private val config: FooConfiguration
) {
private val quoteOrderEndpoint = "/api/quote"
private val AUTH_HEADER = "x-foo-bar"
fun quoteOrder(quoteRequest: QuoteOrderRequest): Single<QuoteOrderResponse> {
val body = JsonFormat.printer().print(quoteRequest)
val httpRequest = HttpRequest.POST<Any>(quoteOrderEndpoint, body)
.header(AUTH_HEADER, config.apiKey)
return httpClient.exchange(httpRequest, String::class.java)
.map { response ->
val builder = QuoteOrderResponse.newBuilder()
JsonFormat.parser().merge(response.body(), builder)
builder.build()
}.singleOrError()
}
}
#ConfigurationProperties("${ServiceHttpClientConfiguration.PREFIX}.foo")
class FooConfiguration {
lateinit var apiKey: String
}
and here is the test code:
class FooClientTest {
lateinit var client: FooClient
lateinit var config: FooConfiguration
#BeforeAll
fun setup() {
val rxHttpClient = RxHttpClient.create(URL("https://sandbox.foo.com"))
config = FooConfiguration()
config.apiKey = "***"
client = FooClient(rxHttpClient, config)
}
#Test
fun testQuoteOrder() {
// This payload is incomplete and the API returns a 310 error.
val request = QuoteOrderRequest.newBuilder()
.build()
val response = client.quoteOrder(request).blockingGet()
assertEquals(request.customer.country, response.customer.country)
}
}
Here is the full stack trace:
17:00:41.446 [multithreadEventLoopGroup-1-2] WARN i.n.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.lang.IllegalArgumentException: Invalid HTTP status code: 310
at io.micronaut.http.HttpStatus.valueOf(HttpStatus.java:146)
at io.micronaut.http.client.FullNettyClientHttpResponse.<init>(FullNettyClientHttpResponse.java:82)
at io.micronaut.http.client.DefaultHttpClient$10.channelRead0(DefaultHttpClient.java:1764)
at io.micronaut.http.client.DefaultHttpClient$10.channelRead0(DefaultHttpClient.java:1725)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.micronaut.http.netty.stream.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:185)
at io.micronaut.http.netty.stream.HttpStreamsClientHandler.channelRead(HttpStreamsClientHandler.java:180)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1429)
at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1199)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1243)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:441)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
17:00:41.463 [multithreadEventLoopGroup-1-2] WARN io.sentry.dsn.Dsn - *** Couldn't find a suitable DSN, Sentry operations will do nothing! See documentation: https://docs.sentry.io/clients/java/ ***
17:00:41.470 [multithreadEventLoopGroup-1-2] WARN io.sentry.DefaultSentryClientFactory - No 'stacktrace.app.packages' was configured, this option is highly recommended as it affects stacktrace grouping and display on Sentry. See documentation: https://docs.sentry.io/clients/java/config/#in-application-stack-frames
io.micronaut.http.client.exceptions.ReadTimeoutException: Read Timeout
at io.micronaut.http.client.exceptions.ReadTimeoutException.<clinit>(ReadTimeoutException.java:26)
at io.micronaut.http.client.DefaultHttpClient.lambda$null$28(DefaultHttpClient.java:1071)
at io.reactivex.internal.operators.flowable.FlowableOnErrorNext$OnErrorNextSubscriber.onError(FlowableOnErrorNext.java:103)
at io.reactivex.internal.operators.flowable.FlowableTimeoutTimed$TimeoutSubscriber.onTimeout(FlowableTimeoutTimed.java:139)
at io.reactivex.internal.operators.flowable.FlowableTimeoutTimed$TimeoutTask.run(FlowableTimeoutTimed.java:170)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
So, the questions are:
1) How can I add custom status codes to the HTTP client.
2) How to avoid the request timeout and throw directly.
This is a bug in http-client and there is, apparently, no workaround.
https://github.com/micronaut-projects/micronaut-core/issues/2189

Error creating Command handler bean post processor in Axon + distributed command bus + eureka

I'm trying to move axon from a SimpleCommandBus to a DistributedCommandBus with Eureka for service discovery.
I tried implementing this by going through the documentation provided under axon (https://docs.axoniq.io/reference-guide/extensions/spring-cloud)
When I try starting my application, I'm receiving an error with the message
Error creating bean with name '__axon-annotation-command-handler-bean-post-processor': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
This is how I'm wiring up the distributed command bus:
public CommandRouter springCloudCommandRouter(DiscoveryClient discoveryClient, Registration localServiceInstance) {
return SpringCloudCommandRouter.builder()
.discoveryClient(discoveryClient)
.routingStrategy(new AnnotationRoutingStrategy(STATIC_KEY))
.localServiceInstance(localServiceInstance)
.build();
}
#Bean
public CommandBusConnector springHttpCommandBusConnector(
#Qualifier("localSegment") CommandBus localSegment,
RestOperations restOperations,
Serializer serializer) {
return SpringHttpCommandBusConnector.builder()
.localCommandBus(localSegment)
.restOperations(restOperations)
.serializer(serializer)
.build();
}
#Primary
#Bean
public DistributedCommandBus springCloudDistributedCommandBus(
CommandRouter commandRouter,
CommandBusConnector commandBusConnector) {
return DistributedCommandBus.builder()
.commandRouter(commandRouter)
.connector(commandBusConnector)
.build();
}
After starting my application with this, I'm receiving the following error message.
2019-07-04T14:02:39.079+05:30 [APP/PROC/WEB/0] [OUT] 2019-07-04 08:32:39.079 WARN 17 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '__axon-annotation-command-handler-bean-post-processor': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
2019-07-04T14:02:39.100+05:30 [APP/PROC/WEB/0] [OUT] Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-04T14:02:39.100+05:30 [APP/PROC/WEB/0] [OUT] 2019-07-04 08:32:39.099 INFO 17 --- [ main] ConditionEvaluationReportLoggingListener :
2019-07-04T14:02:39.106+05:30 [APP/PROC/WEB/0] [OUT] 2019-07-04 08:32:39.106 ERROR 17 --- [ main] o.s.boot.SpringApplication : Application run failed
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] ... 23 common frames omitted
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1331)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1471)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1491)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:248)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:174)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:177)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:294)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.CachedIntrospectionResults.buildGenericTypeAwarePropertyDescriptor(CachedIntrospectionResults.java:359)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.beans.GenericTypeAwarePropertyDescriptor.<init>(GenericTypeAwarePropertyDescriptor.java:106)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.core.GenericTypeResolver.resolveParameterType(GenericTypeResolver.java:61)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.core.ResolvableType.resolveMethodParameter(ResolvableType.java:1297)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.core.ResolvableType.as(ResolvableType.java:443)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at org.springframework.core.ResolvableType.getSuperType(ResolvableType.java:453)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at java.lang.Class.getGenericSuperclass(Class.java:777)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.repository.ClassRepository.getSuperclass(ClassRepository.java:90)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:92)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:51)
2019-07-04T14:02:39.107+05:30 [APP/PROC/WEB/0] [OUT] at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:58)
The dependencies which we are using in our spring boot app is as
<spring-boot.version>2.0.6.RELEASE</spring-boot.version>
<spring.cloud.version>Finchley.RELEASE</spring.cloud.version>
<axon.version>4.0</axon.version>
<axon-spring-boot-starter.version>${axon.version}</axon-spring-boot-starter.version>
<axon-springcloud.version>4.0</axon-springcloud.version>
<axon-distributed-commandbus-springcloud.version>3.4.3</axon-distributed-commandbus-springcloud.version>
UPDATE:
We tried bumping our axon version to 4.1.2, we are now encountering a 404 error. Stack trace below:
2019-07-17 07:02:48.815 DEBUG [test-app,65da6028861139c5,150e2f6a196c6ce8,false] 19 --- [http-nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Written [{timestamp=Wed Jul 17 07:02:48 UTC 2019, status=404, error=Not Found, message=No message available, path=/spring-command-bus-connector/command}]
We also tried moving the command router from SpringCloudCommandRouter -> SpringCloudHttpBackupCommandRouter, but to no avail.
Any help on this would be greatly appreciated.
I hope I can help you out with the problem you're encountering.
The __axon-annotation-command-handler-bean-post-processor is a Bean Post Processor Axon Framework introduces to be able to correctly register all Command Handlers you might have set up in your application.
Depending on the version of Axon Framework your utilizing however, this might be dealt with differently.
If you're in an Axon 3.x application, you might be leveraging the #EnableAxon annotation to auto-configure all the Axon niceties for you.
When you are however also using the axon-spring-boot-starter dependency to have Spring Boot like auto configuration, you are not required to use the #EnableAxon. It's actually suggested to not use both in this scenario.
To be clearer about this, Axon 4 has dropped the the notion of the #EnableAxon altogether.
Granted, I am sharing this info as you're linking to an Axon 3.x Reference Guide page and hence I am assuming you are using Axon 3. If that's the case, I suggest you either use the #EnableAxon or the axon-spring-boot-starter dependency.
If you are on another version of Axon, I'd like to ask you to update the question to specify the version of the framework and of Spring, and any other important configuration pointers which might help us resolve the problem at hand.
Concluding, I hope this helps you out #Anish!
Update
I think I know what the issue is you're encountering #Anish.
You're using Axon Framework 4.0 (which you can by the way update to 4.1.2, pretty sure there's no pain in doing so), but you are still utilizing the axon-distributed-commandbus-springcloud of Axon Framework 3.4.3.
When Axon Framework moved from version 3.x to 4.x, a few modules have been removed from the core repository. Modules like axon-amqp, axon-mongo, but also axon-distributed-commandbus-springcloud. The reasoning behind this is to have independent release cycles for the core and these 'extensions'.
If you want to use an Axon 4 compliant Spring Cloud CommandBus, it is suggested to pull in the Axon Spring Cloud Extension instead.
I assume that as soon as you switch that dependency around, that the issue will be resolved.

Junit tests fail because of Elasticsearch

I have a Junit test class in a Spring Boot project that tests the methods of a CRUD, when I open the test class by NetBeans -> right button -> Test File tests run perfectly, but when I right click on package and select Test Package the first test runs and the second one that is the file I quoted at startup fails completely (same error happens withmvn clean package or mvn test).
It seems to me to be some error related to the elasticsearch directory used in the tests.
This is the application.yml of the test environment:
eureka:
client:
enabled: false
instance:
appname: account
instanceId: account:${spring.application.instance-id:${random.value}}
spring:
application:
name: account
cache:
type: simple
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:account;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
name:
username:
password:
hikari:
auto-commit: false
jpa:
database-platform: io.github.jhipster.domain.util.FixedH2Dialect
database: H2
open-in-view: false
show-sql: false
hibernate:
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
properties:
hibernate.id.new_generator_mappings: true
hibernate.connection.provider_disables_autocommit: true
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
hibernate.hbm2ddl.auto: create-drop
hibernate.jdbc.time_zone: UTC
data:
elasticsearch:
properties:
path:
home: target/elasticsearch
liquibase:
contexts: test
mail:
host: localhost
messages:
basename: i18n/messages
mvc:
favicon:
enabled: false
thymeleaf:
mode: HTML
server:
port: 10344
address: localhost
# ===================================================================
# JHipster specific properties
#
# Full reference is available at: https://www.jhipster.tech/common-application-properties/
# ===================================================================
jhipster:
async:
core-pool-size: 1
max-pool-size: 50
queue-capacity: 10000
# To test logstash appender
logging:
logstash:
enabled: true
host: localhost
port: 5000
queue-size: 512
security:
authentication:
jwt:
# This token must be encoded using Base64 (you can type `echo 'secret-key'|base64` on your command line)
base64-secret: 783h78fh374h78h78dh278hd78dh3782dh3h278d3hd78h78dh378dh3h3782hd8h28dh8hd2782hd8h=
# Token is valid 24 hours
token-validity-in-seconds: 86400
client-authorization:
access-token-uri: http://uaa/oauth/token
token-service-id: uaa
client-id: internal
client-secret: internal
metrics:
logs: # Reports metrics in the logs
enabled: true
report-frequency: 60 # in seconds
The error:
2019-07-11 18:37:44.649 WARN 11610 --- [ main] c.f.account.config.CacheConfiguration : No discovery service is set up, Hazelcast cannot create a cluster.
2019-07-11 18:37:44.715 WARN 11610 --- [ main] com.hazelcast.instance.Node : [172.31.0.1]:5701 [dev] [3.9.4] No join method is enabled! Starting standalone.
2019-07-11 18:37:45.608 WARN 11610 --- [ main] c.f.a.s.o.UaaSignatureVerifierClient : could not contact UAA to get public key
2019-07-11 18:37:45.708 INFO 11610 --- [ main] c.f.account.config.CacheConfiguration : Closing Cache Manager
18:37:45.734 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [com/mycompany/account/config/ElasticsearchConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClient' defined in class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-name6ab7716d-f145-41dd-927f-b83333089285]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:733) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:475) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.8.RELEASE.jar:2.0.8.RELEASE]
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127) [spring-boot-test-2.0.8.RELEASE.jar:2.0.8.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) [spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) [spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418) [surefire-booter-2.22.1.jar:2.22.1]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClient' defined in class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-name6ab7716d-f145-41dd-927f-b83333089285]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-name6ab7716d-f145-41dd-927f-b83333089285]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-name6ab7716d-f145-41dd-927f-b83333089285]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:265) ~[elasticsearch-5.6.14.jar:5.6.14]
at org.elasticsearch.node.Node.<init>(Node.java:265) ~[elasticsearch-5.6.14.jar:5.6.14]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$InternalNode.<init>(ElasticsearchJestAutoConfiguration.java:199) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration.createInternalNode(ElasticsearchJestAutoConfiguration.java:167) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration.testClient(ElasticsearchJestAutoConfiguration.java:81) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$$EnhancerBySpringCGLIB$$8f46f0b2.CGLIB$testClient$1(<generated>) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$$EnhancerBySpringCGLIB$$8f46f0b2$$FastClassBySpringCGLIB$$e4311738.invoke(<generated>) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.12.RELEASE.jar:5.0.12.RELEASE]
mework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:725) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
... 45 more
18:37:45.745 [main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#4a801c2a] to prepare test instance [com.mycompany.account.web.rest.UserSystemResourceIntTest#3f5b4923]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) ~[spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) ~[spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) ~[spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) ~[spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246) [spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227) [spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) [spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) [spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246) [spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) [spring-test-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [com/mycompany/account/config/ElasticsearchConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClient' defined in class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-name6ab7716d-f145-41dd-927f-b83333089285]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:733) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:475) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClient' defined in class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-name6ab7716d-f145-41dd-927f-b83333089285]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-name6ab7716d-f145-41dd-927f-b83333089285]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-name6ab7716d-f145-41dd-927f-b83333089285]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:265) ~[elasticsearch-5.6.14.jar:5.6.14]
at org.elasticsearch.node.Node.<init>(Node.java:265) ~[elasticsearch-5.6.14.jar:5.6.14]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$InternalNode.<init>(ElasticsearchJestAutoConfiguration.java:199) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration.createInternalNode(ElasticsearchJestAutoConfiguration.java:167) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration.testClient(ElasticsearchJestAutoConfiguration.java:81) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$$EnhancerBySpringCGLIB$$8f46f0b2.CGLIB$testClient$1(<generated>) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$$EnhancerBySpringCGLIB$$8f46f0b2$$FastClassBySpringCGLIB$$e4311738.invoke(<generated>) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365) ~[spring-context-5.0.12.RELEASE.jar:5.0.12.RELEASE]
at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$$EnhancerBySpringCGLIB$$8f46f0b2.testClient(<generated>) ~[spring-boot-starter-data-jest-3.1.5.RELEASE.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_211]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.12.RELEASE.jar:5.0.12.RELEASE]
To discard permission in the directory, in the target/data folder I run command chmod -R 777.
Edited
I'm doing some tests for deletion, I removed #MockBean notations from the global instances and the error stopped happening (there must be some conflict), but how to do mock without #MockBean?
You need to add this to src/test/resources/config/application.yml:
spring:
data:
elasticsearch:
properties:
node:
max_local_storage_nodes: 2
see: https://github.com/jhipster/generator-jhipster/issues/10302

I am getting below error when start apache tomcat with spring-boot

when I started apache tomcat with spring boot I am getting below exception my component scan and some other annotation :
#ComponentScan(basePackages =
{"com.ce.resources","com.ce.services","com.ce.repository"})
#EnableJpaRepositories("com.ce.repository")
#EntityScan("healthchecker")
#SpringBootApplication
2018-10-01 14:22:21.000 WARN 14044 --- [ost-startStop-1] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userprofileResource' defined in file [D:\appache\apache-tomcat-8.5.34\webapps\ng-ols-platformservice\WEB-INF\classes\com\ce\resources\UserprofileResource.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userProfileService' defined in file [D:\appache\apache-tomcat-8.5.34\webapps\ng-ols-platformservice\WEB-INF\classes\com\ce\services\UserProfileService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userProfileRespository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.ce.entity.UserProfile
2018-10-01 14:22:21.000 INFO 14044 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-10-01 14:22:21.010 INFO 14044 --- [ost-startStop-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-10-01 14:22:21.029 INFO 14044 --- [ost-startStop-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2018-10-01 14:22:21.051 INFO 14044 --- [ost-startStop-1] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-10-01 14:22:21.080 ERROR 14044 --- [ost-startStop-1] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userprofileResource' defined in file [D:\appache\apache-tomcat-8.5.34\webapps\ng-ols-platformservice\WEB-INF\classes\com\ce\resources\UserprofileResource.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userProfileService' defined in file [D:\appache\apache-tomcat-8.5.34\webapps\ng-ols-platformservice\WEB-INF\classes\com\ce\services\UserProfileService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userProfileRespository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.ce.entity.UserProfile
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245) [catalina.jar:8.5.34]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.5.34]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754) [catalina.jar:8.5.34]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730) [catalina.jar:8.5.34]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) [catalina.jar:8.5.34]
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985) [catalina.jar:8.5.34]
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857) [catalina.jar:8.5.34]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_91]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
Enable jpa repositories to make spring-boot aware that where to find repositories.
#EnableJpaRepositories("com.ce.repository")
Refer this for more info : https://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/config/EnableJpaRepositories.html

PCF - No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String]

Spring Boot application works normal when we run it locally, However if its deployed in PCF, getting below exception:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String]
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:324)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.cloud.netflix.archaius.ConfigurableEnvironmentConfiguration.getProperty(ConfigurableEnvironmentConfiguration.java:61)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at com.fdc.ucom.fdcgatewaymockutil.endpoint.ConfigurationController.getProperties(ConfigurationController.java:35)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at com.fdc.ucom.fdcgatewaymockutil.endpoint.ConfigurationController.lambda$getConfig$1(ConfigurationController.java:58)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at java.util.Iterator.forEachRemaining(Iterator.java:116)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1038)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1021)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at java.lang.reflect.Method.invoke(Method.java:498)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
You can create a custom converter as follows:
#Component
public class LinkedHashMap2String implements Converter<LinkedHashMap, String> {
#Override
public String convert(LinkedHashMap source) {
return source.toString();
}
}
And then add this convertor into the GenericConversionList as follows:
#Configuration
public class SpringConvertors {
#Bean
public ConversionService conversionService(LinkedHashMap2String linkedHashMap2String) {
ConversionServiceFactoryBean conversionServiceFactory = new ConversionServiceFactoryBean();
conversionServiceFactory.setConverters(Sets.newHashSet(linkedHashMap2String);
conversionServiceFactory.afterPropertiesSet();
return conversionServiceFactory.getObject();
}
}

Resources