0

I saw several questions like this, but I am not quite sure to run Spring Boot properly in terms of JMX. Here my error at the console:

2020-07-24 09:54:10.243 ERROR 14272 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Failed to register LiveBeansView MBean; nested exception is javax.management.InstanceAlreadyExistsException: DefaultDomain:application=
    at org.springframework.context.support.LiveBeansView.registerApplicationContext(LiveBeansView.java:84) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:901) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.8.RELEASE.jar:2.2.8.RELEASE]
    at com.practicas.conexiona.ConexionaApplication.main(ConexionaApplication.java:22) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.8.RELEASE.jar:2.2.8.RELEASE]
Caused by: javax.management.InstanceAlreadyExistsException: DefaultDomain:application=
    at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437) ~[na:1.8.0_251]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898) ~[na:1.8.0_251]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966) ~[na:1.8.0_251]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900) ~[na:1.8.0_251]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324) ~[na:1.8.0_251]
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522) ~[na:1.8.0_251]
    at org.springframework.context.support.LiveBeansView.registerApplicationContext(LiveBeansView.java:80) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    ... 13 common frames omitted


Process finished with exit code 0

And this is my application.properties:

server.port=9898

spring.jpa.database=MYSQL
spring.datasource.url=jdbc:mysql://xxxxxxxxxxxxxxxxxxxxxx
spring.datasource.username=practicas
spring.datasource.password=practicas2020
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.generate-ddl=false

#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE 

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

spring.profiles.active=application.properties

spring.jmx.enabled = false
#endpoints.jmx.unique-names = true

spring.jmx.default-domain=xxxxapplication
endpoints.jmx.domain=xxxxapplication

spring.application.admin.enabled=true

This is my pom.xml right now:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>xxxxxxxx</groupId>
    <artifactId>xxxxxxxxxxxx</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>crmiguez-project</name>
    <description>Spring Boot Project</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.197</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.4.2.Final</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.2.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.2.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.49</version>
        </dependency>


        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>angularjs</artifactId>
            <version>1.8.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-dbcp</artifactId>
            <version>9.0.1</version>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>

        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>javax.transaction-api</artifactId>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

I have tried on deleting Tomcat and restarting, yet it gets the same error. Any factible solution for this scenery, please?

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Hi everyone, good morning. I am still tried to run Spring Boot properly, but it is not working. :( Please, any volunteer to help me? I wiil appreciate it! :) –  Jul 27 '20 at 07:18
  • It is hard to help you with the information you've provided. Is this application deployed as war on tomcat with other applications in the same instance? What Spring Boot version is this? – Stephane Nicoll Jul 27 '20 at 08:12
  • @StephaneNicoll Maybe the pom.xml gives you more help. I edit the question on that. Sorry if I explain in a weird way, I am newbie on that tool. :P –  Jul 27 '20 at 08:34
  • There are a number of issues in the pom but none that explains what you're experiencing. You shouldn't override all those version as they are provided by Spring Boot. You are mixing two different Spring Boot versions in the same project. We can't help you effectively without the information that we need. Can you share a small sample on a GitHub repository that showcases the problem? It doesn't have to be your app, just a small sample. – Stephane Nicoll Jul 27 '20 at 08:50
  • Of course, @StephaneNicoll, hang on a second. –  Jul 27 '20 at 08:59
  • Here you are, sir. Please take a look. –  Jul 27 '20 at 09:15
  • There is no link I can see here. If you can make the repo public that would be easier as it lets others in the community help you. – Stephane Nicoll Jul 27 '20 at 11:31
  • https://github.com/crmiguez/springboot_sample –  Jul 27 '20 at 15:35
  • There is a configuration on Intellij IDEA that Application.class is a default one. In this class, you are permitted to change code manually. If you migrate modules and a new Application, it throws the exception I put in the beginning of the question. –  Jul 27 '20 at 15:47
  • How do I reproduce the issue? I've started the project above and it worked for me. – Stephane Nicoll Jul 27 '20 at 15:55
  • In Intellij IDEA, has a corner with the Application and the run icon. It works if the button changes to a rerun button, but it does not with me. –  Jul 27 '20 at 16:00
  • Sorry, that works for me too. – Stephane Nicoll Jul 27 '20 at 16:01

1 Answers1

0

There was a conflict between versions in Intellij IDEA, from 2020.1.2 to 2020.1.4. So I decided to update the latest version and it gets the JMX properly fixed. @Stephane Nicoll thanks so much for your patience and my apologies with the inconveniece during this day. Best regards from Spain to Belgium.

  • @Stephane Nicoll Good morning. For company's privacy, I have to delete the repository. I hope this kind of issues took in consideration for linking Spring Boot to the different IDEs. Thanks so much again for your help! :) –  Jul 28 '20 at 07:15