最近的一个项目需要对外提供webservice接口,项目部署后,客户端访问报错:Cannot create a secure XMLInputFactory,当时领导催着赶进度,真让人头大,有如下解决方案:
方案一
添加如下依赖:
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.4.1</version>
</dependency>
方案二
- 调整jar包加载顺序
方案XXX
** @@@@@@@@ **
终极方案
- 添加监听器
public class SealManageListener implements ServletContextListener {
private static final Logger logger = LoggerFactory.getLogger(SealManageListener.class);
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
Properties props = System.getProperties();
props.setProperty("org.apache.cxf.stax.allowInsecureParser", "1");
logger.debug("系统初始化设置.....");
props.setProperty("UseSunHttpHandler", "true");
}
}
- 再添加web.xml的配置
<listener>
<listener-class>xxx.xxx.xxx.filter.SealManageListener</listener-class>
</listener>