My actuators in spring boot are not working - java

I am trying to check whether my spring boot application is up and running via spring boot actuators. My spring boot application annotation contains this:
#SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
WebMvcAutoConfiguration.class,
HibernateJpaAutoConfiguration.class EntityManagerFactory
})
In my application properties file I have management.server.port=8081. But when I start up my application and try to run localhost:8081/actuator/info I got an error - This site can not be reached.
What am I doing wrong ?
Thank you for any help.

Related

DAO test case getting failed

DAO test cases getting failed due to below error:
Caused by: java.lang.ClassNotFoundException: de.flapdoodle.embed.process.config.RuntimeConfig
we are using spring boot 2.7.3 version , Spring data mongoDB :3.4.2, MongoDB :4.2,
de.flaodoodle.embeded.mongo-2.2.0, de.flaodoodle.embeded.process-2.1.2
Please help for the same
Try adding this to your spring boot application:
#SpringBootApplication(exclude = EmbeddedMongoAutoConfiguration.class)
It will disable auto configuration as that causes issues. You can use your own configuration in this case.

JUnit is failing after upgrading to Spring boot 2.3

Upgrading my Application from Spring boot 2.1.6 to Spring boot 2.3
After adding this property in my Yaml file, I am able to run my application
Spring.main.allow-bean-definition-overriding: true
But even after same property in my yml file , getting following error , any clue will be appreciated
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException at DefaultListableBeanFactory.java:995
for reference this is my sample Junit class
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
#ActiveProfiles("local,test")
#DirtiesContext
public class ControllerContextTest {
}

Java : spring-boot-starter-data-jpa dependency in a dependent project

I have build two projects using Java
myproject-db - for db interactions
myproject-api - for exposing api calls
myproject-db uses spring-boot-starter-data-jpa as a dependency and I am able to build and install it all fine.
myproject-api - is a spring boot project and it uses myproject-db as a dependency. When I run my myproject-api project it gives me error
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
I have defined my dataSource url application.properties file in myproject-db like below
spring.datasource.url=jdbc:mysql://localhost:3306/somedb?useSSL=false
spring.datasource.username=root
spring.datasource.password=somepass
application.properties file of myproject-api is empty.
Question is why am I getting this error.
You should have one delivery application configured with Spring Boot with dependent modules
You can have for example
myproject-parent
|
myproject-api
myproject-ui
If your delivery project (main war/jar) is myproject-api then application.properties and #Configuration must be configured in myproject-api and in #SpringBootApplication scope
You cannot have two #SpringBootApplication scopes

Spring Cloud Config in web application

I have legacy Java web application (with Spring MVC and web.xml) which are deployed in Tomcat. I want to swtich configuration to Spring Cloud Config.
Structure of this application (just simplify it for example) - jar file with Spring Controller and services, which I want to do Spring Cloud Config compatible. And another module with web.xml, which add jar as dependency.
I added bootstrap.yml with application name to module, which packaged to jar in "resources" folder and add "EnableAutoConfiguration" and "SpringBootApplication" annotations, but got exception:
java.lang.IllegalArgumentException: Could not resolve placeholder 'foo' in string value "${foo}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:219)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:193)
Config server is run. I wrote simple client, which I run via main method and it works, but when I deploy legacy app in Tomcat - it doesn't work.
Can someone help with it?

Spring Boot and Spring Security integration in embedded Jetty environment

I'm trying to initialize Spring Security from a main() method in a "fat" executable JAR with Spring Boot and embedded Jetty.
I use Spring Security with Java config (no web.xml). The problem is that embedded Jetty fails to register the springSecurityFilterChain filter.
When I run the same JAR as a WAR in Jetty (mvn jetty:run) it works normally and I see this:
Initializing Spring embedded WebApplicationContext
But when running in embedded Jetty I see no WebApplicationContext getting initialized.
I have this EmbeddedServletContainerFactory:
#Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
factory.setPort(8080);
factory.addServerCustomizers(new JettyServerCustomizer() {
public void customize(Server server) {
// TODO: INITIALIZE SPRING SECURITY SOMEHOW...
}
});
return factory;
}
I've tried creating a subclass of AbstractSecurityWebApplicationInitializer but it is in conflict with my SpringBootServletInitializer. In my pom.xml I have these dependencies:
spring-boot-starter-jetty
spring-boot-starter-logging
spring-boot-starter
When I add spring-boot-web it throws:
java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
Also I tried to register the DelegatingFilterProxy with Jetty but then it throws:
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
I'm guessing I need to tell Jetty to use WebApplicationContext, but how?
Your setup disables Spring Boot to do its magic. Instead of setting up the container yourself let Spring Boot handle it. You can simply add your JettyServerCustomizer to the configuration as a #Bean. This will execute it and you can do your registration of whatever you need.
This still allows Spring Boot to do its magic and you have registered the additional endpoint y ou need.
Another solution could be to add the servlet as a ServletRegistrationBean to your configuration it will then automatically be added by Spring Boot.

Categories