依赖项
<dependencies>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>community</artifactId>
<version>2.21-RC</version>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-main</artifactId>
<version>2.21-RC</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>javac-shaded</artifactId>
<version>9+181-r4173-1</version>
</dependency>
</dependencies>
配置文件
applicationContext.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Spring will reference the instance of the HelloWorld class
by the id name "helloService" -->
<bean id="helloService" class="HelloWorld"/>
<!-- This creates a Service descriptor, which allows the org.geoserver.ows.Dispatcher
to locate it. -->
<bean id="helloService-1.0.0" class="org.geoserver.platform.Service">
<!-- used to reference the service in the URL -->
<constructor-arg index="0" value="hello"/>
<!-- our actual service POJO defined previously -->
<constructor-arg index="1" ref="helloService"/>
<!-- a version number for this service -->
<constructor-arg index="2" value="1.0.0"/>
<!-- a list of functions for this service -->
<constructor-arg index="3">
<list>
<value>sayHello</value>
</list>
</constructor-arg>
</bean>
</beans>
源码示例
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorld {
public HelloWorld() {
// Do nothing
}
public void sayHello(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getOutputStream().write("Hello world".getBytes());
}
}