1.需要在启动命令添加相关jvm参数
-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname -Dcom.sun.management.jmxremote.port -Dcom.sun.management.jmxremote.authenticate -Dcom.sun.management.jmxremote.ssl
具体示例:
java -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.port= -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar ems-service-user-2.0..jar
2.在web项目 web.xml添加:
<servlet>
<servlet-name>DruidStatView</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> <!-- 远程访问JavaSE项目使用jmx连接 -->
<init-param>
<param-name>jmxUrl</param-name>
<param-value>service:jmx:rmi:///jndi/rmi://127.0.0.1:9004/jmxrmi</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DruidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
访问地址:
http://127.0.0.1:8080/web项目名/druid/index.html 即可
cmd查找端口pid,杀pid
netstat -aon|findstr "" taskkill /t /f /pid