How do I enable H2 Console in a Spring Boot Library? - spring-boot

I have a non-web Spring Boot Library which has persistence entities that will be used by web application clients to communicate with the database. When I create my tests, I'm using #SpringBootTest in my spring integration tests, thus simulating a spring boot application using my library.
When setting the spring.h2.console.enabled to true, I thought I would be able to debug through my integration tests and have the H2 console enabled so that I can peer into the data by going to http://localhost:8080/h2-console, but the console doesn't load in my browser.
I have suspicions that this is somehow related to the fact that since my library is not a web-mvc library, it isn't auto configuring the H2 WebServlet, but I would like to know if providing the property would be enough for spring boot to auto configure the servlet.
Does anyone know if providing the H2 property would be enough? Or do I need to do something to enable the H2 WebServlet to be enabled?

I managed to get it working (somewhat) by adding a webEnvironment entry in the #SpringBootTest annotation. This allowed the H2 WebServlet to be registered. The reason that I said "somewhat" was because whenever I debug the test, the thread seems to suspend and I get very delayed response times from H2 when requesting it in my browser (http://localhost:8080/h2-console). My H2 database is very small (500 KB) so I would assume this has something to do with the server being embedded and tied to the test somehow?

Related

in microservice not able to run client with spring framework?

0
i am using jdk 1.8 only and the problem is not during server run. It is during a client run and for normal client works fine. Problem starts when whole of spring framework(includes security, audit, data jpa and JWT).
For me also works with client with only one main string class, but starts when whole of spring framework application.
All examples on net are found only with one class.
what do i do for this???

Spring boot LDAP auto configuration - anonymous access

If the ldap server allows anonymous access, how do I configure the following properties.
spring.ldap.username
spring.ldap.password
If I leave out these properties, I am getting null pointer exception as internally hashtable is used.
I run in the same problem with a transient dependency of Spring ldap security from another project and Spring boot 2.1 and Spring boot admin. My LDAP is not configured (with Spring boot) and a Spring boot admin console initiates a health check. Because of Spring boot auto-configuration a LDAP health check bean is enabled and then the check runs into a NullPointerException.
For this case I excluded the LdapHealthIndicatorAutoConfiguration.class via #SpringBootApplication.
For your problem your maybe need more excludes. Please refer https://docs.spring.io/spring-boot/docs/current/reference/html/auto-configuration-classes.html for existing auto configuration classes. Search for LDAP and try to exclude the found classes in your application.
I'm pretty sure this is a bug in Spring LDAP security, because an anonymous LDAP configuration (no user and password) was intended to work.
I think, this should able to use. Just don't provider membership detail.

how to connect with gemfire running on local machine using spring data gemfire with annoatations

I have tried so many demos but I am not able to create region on my local gemfire .
my code is running in embedded mode but I want to run it as client server mode with using annotions how should I do this.
Thanks.
Your problem description is pretty vague.
You should have a look at my pivotal-gemfire-clientserver-examples that compares and contrasts using native GemFire configuration (both cache.xml and then using GemFire's Java API) vs. Spring configuration (again using both Spring XML as well as Spring Java configuration meta-data).
For instance, you can see here that I configured and bootstrapped a GemFire Server using Spring Boot along with a Java configuration class. The GemFire cache client is my test class (along with the client-side Java config), but easily could have been another standalone, Spring Boot application.
Another, interesting tidbit, is that you can connect to the Spring Boot, GemFire Server application using Gfsh once the server is up and running. To connect in gfsh, use...
gfsh>connect --jmx-manager=localhost[1199]
Hope this helps!
-John

Spring Cloud Netflix - how to access Eureka/Ribbon from traditional web app?

Everything I found on the internet about Spring Cloud Netflix is about running microservices from Boot applications using #EnableEurekaClients and so on.
Now I'm trying to connect my logging microservice within a traditional war application (springmvc, jaxws etc) - piece of legacy which can not be converted to Boot or modified in any way (by technical task).
I've created a new maven module "log-server-client" that knows nothing about upper web layer and intended to be used as a simple dependency in any maven project.
How should I configure access to Spring Cloud Netflix for this simple dependency? At least, how to configure Eureka and Ribbon?
I just extracted some lines of code from RestTemplate and created my custom JmsTemplate (microservice works with jms remoting with apache camel and activemq), exactly how it is done in RestTemplate, but this code stil lacks connection to infrastructure
afaik, we can create a global singleton bean, run a separate thread from this bean, and run Boot app from this thread, but don't you think that it is very ugly and can lead to problems? How it really should be used?
Great question!
One approach is to use a "sidecar". This seems to be a companion Spring Boot application that registers with the Eureka Server on behalf of your traditional web app.
See e.g.:
http://www.java-allandsundry.com/2015/09/spring-cloud-sidecar.html
http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html#_polyglot_support_with_sidecar
Another approach is to use the following library:
"A small lib to allow registration of legacy applications in Eureka service discovery."
https://github.com/sawano/eureka-legacy-registrar
This library can be used outside of Spring Boot.

With Spring do you still need a java application server and when?

looks to me you need tomcat or some other servlet engine for the web part.
what about data access part using hibernate and jms? Thanks.
No, you don't need an application server, you can see Spring as a proprietary, modular application server implementation / adapter. But you still need an a servlet container.
Data access part: you can use hibernate and some standalone connection pool
jms: Spring is not a JMS provider, but it nicely integrates POJOs with any JMS provider
Spring also has comprehensive transactions support
Finally you have jmx and aop support built-in and easy integration with bean validation, jpa, web services, rmi, jci, task scheduling, caching...
As you can see you can either use certified application server and Java EE stack or built on top of Tomcat and pick Spring modules you need. Sometimes Spring uses standard Java EE APIs (like JPA), more often it builts its own.

Resources