2

我有Spring项目。我需要使用JMX. 我正在使用simplejmx- 我发现它非常有用,但不幸的是,我无法管理一些基本的事情。

我写了一个非常简单的服务器:

package com.pckg.jmx;

import com.j256.simplejmx.web.JmxWebServer;

public class JMXServer {

    public static void main(String[] args) throws Exception {

        JmxWebServer jmxWebServer = new JmxWebServer(8123);
        jmxWebServer.start();
    }

}

pom.xml

<project...> 

    <properties>
        <jetty-version>8.1.9.v20130131</jetty-version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>com.j256.simplejmx</groupId>
            <artifactId>simplejmx</artifactId>
            <version>1.8</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>${jetty-version}</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>${jetty-version}</version>
            <optional>true</optional>
        </dependency>

    </dependencies>

</project>

当我运行它时,它运行良好。我想以春天的方式来做。我创建了jmx-config文件:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- publishes classes that have @JmxResource or implement JmxSelfNaming 
        to jmxServer automagically -->
    <bean id="beanPublisher" class="com.j256.simplejmx.spring.BeanPublisher">
        <property name="jmxServer" ref="jmxServer" />
    </bean>

    <!-- our JmxServer which publishes our beans via JMX -->
    <bean id="jmxServer" class="com.j256.simplejmx.web.JmxWebServer"
        init-method="start" destroy-method="stop">
        <!-- the port should probably come from a configured property -->
        <property name="registryPort" value="8123" />
    </bean>

</beans>

我改变了web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    ...
    jmx-config.xml
    </param-value>
</context-param>

我添加了简单的类:

package com.pckg.jmx;

import com.j256.simplejmx.common.JmxResource;

@JmxResource
public class DummyJMX {

    private int var = 3;
}

当我运行我的应用程序时,我看到了警告:

10:15:07,184 WARN  [org.jboss.as.ee] (MSC service thread 1-1) JBAS011006: Not installing optional component org.eclipse.jetty.continuation.Servlet3Continuation$1 due to exception: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011054: Could not find default constructor for class org.eclipse.jetty.continuation.Servlet3Continuation$1
    at org.jboss.as.ee.component.ComponentDescription$DefaultComponentConfigurator.configure(ComponentDescription.java:606)
    at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:81)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_21]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_21]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_21]

10:15:07,191 WARN  [org.jboss.as.ee] (MSC service thread 1-1) JBAS011006: Not installing optional component org.eclipse.jetty.continuation.Servlet3Continuation$2 due to exception: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011054: Could not find default constructor for class org.eclipse.jetty.continuation.Servlet3Continuation$2
    at org.jboss.as.ee.component.ComponentDescription$DefaultComponentConfigurator.configure(ComponentDescription.java:606)
    at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:81)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_21]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_21]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_21]

还有一个例外(太长了,我只粘贴了第一部分):

10:16:54,674 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-13) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beanPublisher' defined in class path resource [jmx-config.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/server/AbstractConnector
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) [spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) [spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) [spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) [spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.6.RELEASE.jar:3.2.6.RELEASE]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_21]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_21]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_21]
Caused by: java.lang.NoClassDefFoundError: org/eclipse/jetty/server/AbstractConnector

我正在寻找解决方案,但我无法解决它的问题。我的想法是问题出在pom.xml但我不确定,此外,我不知道如何检查它以及我应该改变什么。

提前致谢

4

2 回答 2

2

您将 jetty-server 依赖项作为可选,并且如果您将代码打包为 war,则可能(取决于您的 pom 中的其他插件和配置设置)该 jar 不包含在其中。检查生成的 war 文件并<optional>true</optional>在你的 pom 中测试打包以获取 'jetty-server' 依赖项。

于 2014-04-11T09:45:32.703 回答
1

@Andrei Stefan answer solved this problem but anyhow, there is also another problem.

<bean id="jmxServer" class="com.j256.simplejmx.web.JmxWebServer"
    init-method="start" destroy-method="stop">
    <!-- the port should probably come from a configured property -->
    <property name="registryPort" value="8123" />
</bean>

There is no field registryPort in com.j256.simplejmx.web.JmxWebServer: Class JmxWebServer. It should be like this:

<bean id="jmxServer" class="com.j256.simplejmx.web.JmxWebServer"
    init-method="start" destroy-method="stop">
    <!-- the port should probably come from a configured property -->
    <property name="serverPort" value="8123" />
</bean>

I hope this will help somone in the future

于 2014-04-11T12:15:27.890 回答