Creating a Custom Service
package com.my.app @JmxManageable public interface HelloWorldApi extends ExposedApi { @JmxReadable public String getHelloWorldString(); @JmxWritable public String getHelloWorldString(); @JmxInvocable public void helloWorld(); }package com.my.app import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class HelloWorldApiImpl { private Logger log = LoggerFactory.getLogger(HelloWorldApiImpl.class); private String helloWorldString = "hello world"; public String getHelloWorldString() { return helloWorldString; } public void setHelloWorldString(String helloWorldString) { this.helloWorldString = helloWorldString; } public void helloWorld() { log.info(helloWorldString()); } }<?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:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <bean name="sampleService" class="com.bborchard.attiviomodule.SampleAttivioServiceImpl" lazy-init="true" /> <!-- this is the service --> </beans>package com.my.app import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MockHelloWorldApi { private Logger log = LoggerFactory.getLogger(MockHelloWorldApi.class); private String helloWorldString = "hello from junit test"; public String getHelloWorldString() { return helloWorldString; } public void setHelloWorldString(String helloWorldString) { this.helloWorldString = helloWorldString; } public void helloWorld() { log.info(helloWorldString()); } }{ "testAssociations" : { "TestApi" : "com.my.app.MockHelloWorldApi" } }HelloWorldApi helloWorldApi = ServiceFactoryFactory.get().getService(HelloWorldApi.class); helloWorldApi.helloWorld();
Last updated
Was this helpful?