引入Maven包
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Jalena</groupId>
<artifactId>WebServiceTest</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.37</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
</project>
创建接口调用实例
测试类
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xjklAxiService.XjklAxiServiceServiceLocator;
import xjklAxiService.XjklAxiService_PortType;
import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;
public class XjklAxiServiceServiceTest {
private final Logger logger = LoggerFactory.getLogger(getClass());
private XjklAxiService_PortType service;
@Before
public void init(){
XjklAxiServiceServiceLocator locator = new XjklAxiServiceServiceLocator();
try {
service = locator.getxjklAxiService();
} catch (ServiceException e) {
logger.warn(e.getMessage());
}
}
@Test
public void testQry(){
try {
String result = service.YJstockviewQry("##2018-03-01#2018-03-15#");
logger.debug(result);
} catch (RemoteException e) {
logger.warn(e.getMessage());
}
}
}
Log4j2 配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="off" status="INFO"> <!-- 这个status是控制系统信息的输出级别 -->
<Properties>
<Property name="path">${log4j:configParentLocation}/../../logs</Property>
<Property name="pattern" value="%d{DEFAULT} [%-5level] %c{1.}.%M()/%L - %msg%xEx%n"/>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT"> <!-- 将日志信息从控制台输出 -->
<ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY" />
<PatternLayout pattern="%highlight{${pattern}}" />
</Console>
<File name="debug" fileName="${path}/log.log" append="true"> <!-- 将日志信息写入日志文件 -->
<Filters>
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch) -->
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY" />
</Filters>
<PatternLayout pattern="${pattern}" />
</File>
<RollingFile name="warn" fileName="${path}/warn.log" filePattern="${path}/warn-%d{yyyy-MM-dd}_%i.log">
<PatternLayout pattern="${pattern}" />
<SizeBasedTriggeringPolicy size="50MB" />
<Filters>
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch) -->
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY" />
</Filters>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="TestWebService" level="TRACE"/>
<Root level="debug">
<AppenderRef ref="Console" /> <!-- 仅有上述的Appenders配置还不够,这里还不能少,少了就不会在控制台输出 -->
<AppenderRef ref="warn" />
<AppenderRef ref="debug" /> <!-- 仅有上述的Appenders配置还不够,这里还不能少,少了就不会写入文件,但会创建文件 -->
</Root>
</Loggers>
</configuration>
文章评论