springboot集成geoserver-manager

1、pom.xml 依赖


    it.geosolutions
    geoserver-manager
    1.7.0

2、application.properties 配置信息

geoserver.url= http://localhost:8080/geoserver
geoserver.username= admin
geoserver.password= geoserver

3、GeoServerProperties.java 读取配置

@Data
@Configuration
@ConfigurationProperties(prefix = "geoserver")
public class GeoServerProperties {
	private String url;
	private String username;
	private String password;
}

4、GeoServerConfig.java 注入(核心)

@Configuration
public class GeoServerConfig {
	@Autowired
	private GeoServerProperties geoServerProperties;
	@Bean
	public GeoServerRESTManager geoServerRESTManagerFactory() {
		try {
			return new GeoServerRESTManager(new URL(geoServerProperties.getUrl()), geoServerProperties.getUsername(),
					geoServerProperties.getPassword());
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
}

5、测试类

@SpringBootTest
public class GeoServerConfigTest {
	
	@Autowired
    private GeoServerRESTManager geoServerRESTManager;

	@Test
	void testPublishTif() throws Exception {
		GeoServerRESTReader geoServerRESTReader = geoServerRESTManager.getReader();
		
		String workspace = "xiaozhai";
		boolean workspaceNull = geoServerRESTReader.existsWorkspace(workspace);
		System.out.println("workspace是否存在:" + workspaceNull);
	}
}

你可能感兴趣的:(geoserver,GIS,java,spring,boot,geoserver,GIS)