我需要一个解决方案来正确地停止Java中的线程.
我有IndexProcessor实现Runnable接口的类:
public class IndexProcessor implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(IndexProcessor.class);
@Override
public void run() {
boolean run = true;
while (run) {
try {
LOGGER.debug("Sleeping...");
Thread.sleep((long) 15000);
LOGGER.debug("Processing");
} catch (InterruptedException e) {
LOGGER.error("Exception", e);
run = false;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有ServletContextListener开始和停止线程的类:
public class SearchEngineContextListener implements ServletContextListener {
private static final Logger LOGGER = LoggerFactory.getLogger(SearchEngineContextListener.class);
private Thread thread = null;
@Override
public void contextInitialized(ServletContextEvent event) {
thread = new Thread(new …Run Code Online (Sandbox Code Playgroud) 我正在使用Apache CXF cxf-codegen-plugin Maven插件从WSDL文件生成源代码.问题是我JAXBElement<String>生成而不是String.我添加了如下所示的jaxb-bindings.xml文件:
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)
这应该阻止JAXB生成JAXBElement<String>.但它不起作用我仍然JAXBElement<String>生成而不是String.
我的Maven插件看起来像这样:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.runtime.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>${cxf.runtime.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-jaxb</id>
<phase>generate-sources</phase>
<configuration>
<additionalJvmArgs>-Dfile.encoding=UTF8</additionalJvmArgs>
<wsdlOptions>
<wsdlOption>
<wsdl>src/main/resources/wsdl/Cubiks.wsdl</wsdl>
<extraargs>
<extraarg>-b</extraarg>
<extraarg>${basedir}/jaxb-bindings.xml</extraarg>
<extraarg>-b</extraarg>
<extraarg>${basedir}/jaxws-bindings.xml</extraarg>
<extraarg>-exsh</extraarg>
<extraarg>true</extraarg>
<extraarg>-wsdlLocation</extraarg>
<extraarg></extraarg>
</extraargs>
</wsdlOption>
<wsdlOption>
<wsdl>src/main/resources/wsdl/CubiksCallBackService.wsdl</wsdl>
<extraargs>
<extraarg>-b</extraarg>
<extraarg>${basedir}/jaxws-bindings.xml</extraarg>
<extraarg>-b</extraarg>
<extraarg>${basedir}/jaxb-bindings.xml</extraarg>
<extraarg>-exsh</extraarg>
<extraarg>true</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.cubiks.ws.callback</extraarg>
<extraarg>-wsdlLocation</extraarg>
<extraarg></extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration> …Run Code Online (Sandbox Code Playgroud) 当我运行maven clean install它时总是执行所有测试src/test/java是否有办法跳过所有测试,只是为了运行简单的构建而不进行任何测试.
我想要我的测试,src/test/java但我想告诉maven不要执行它们.我一直在网上寻找类似的东西,但我找不到答案.
有没有办法做到这一点?
如果有checkstyle错误,是否有可能以某种方式迫使maven失败?现在我必须运行site目标来生成javadocs和checkstyle报告.我想在install目标上实现它,如果checkstyle有一些错误,我需要构建失败.这有可能实现吗?
现在我有我checkstyle的maven报告块:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>src/test/resources/checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud) 我试图找到将对象传递给Spring MethodInvokingFactoryBean参数列表的方法.这是我的Spring配置:
<bean id="qName" class="javax.xml.namespace.QName">
<constructor-arg index="0" value="${com.groupgti.esb.online.tests.talentq.tns}"/>
<constructor-arg index="1" value="${com.groupgti.esb.online.tests.talentq.serviceName}"/>
</bean>
<bean id="wsdlUrl" class="java.net.URL">
<constructor-arg index="0" value="${com.groupgti.esb.online.tests.talentq.url}"/>
</bean>
<bean id="service" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean id="serviceObject" class="com.groupgti.onlinetest.talentq.jaxb.TQIntegrationV2"/>
</property>
<property name="targetMethod">
<value>create</value>
</property>
<property name="arguments">
<list>
<value type="java.net.URL">wsdlUrl</value>
<value type="javax.xml.namespace.QName">qName</value>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
这不起作用:
<value type="java.net.URL">wsdlUrl</value>
<value type="javax.xml.namespace.QName">qName</value>
Run Code Online (Sandbox Code Playgroud)
我得到了例外:
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.net.URL'; nested exception is java.lang.IllegalArgumentException: Could not retrieve URL for OSGi resource[wsdlUrl|bnd.id=573|bnd.sym=com.groupgti.esb.online.tests.talentq]: OSGi resource[wsdlUrl|bnd.id=573|bnd.sym=com.groupgti.esb.online.tests.talentq] cannot …Run Code Online (Sandbox Code Playgroud) 我在使用<pre>标签时遇到问题<td>.我有JSF数据表和三列.我需要所有三列包含预格式化的文本.
如果我使用<pre>标签,文本会根据需要预先格式化,但列的宽度会比文本大得多.
我可以通过指定white-space: pre-line;in <pre>标签的样式在css中解决这个问题.但它只适用于Firefox和IE,Chrome忽略了这种风格.
所以我的问题是:有没有办法解决<td>其中包含<pre>标签的宽度?
编辑:
我的css课:
.dt_row {
height: 8px;
margin: 3px 3px 3px 3px;
color: #000000;
white-space: pre-line;
}
Run Code Online (Sandbox Code Playgroud)
我的数据表:
<h:dataTable value="#{searchBean.searchResult.concordances}"
var="concordance">
<h:column>
<pre class="dt_row">
#{concordance.left}
</pre>
</h:column>
<h:column>
<pre class="dt_row" style="color: blue;">
#{concordance.middle}
</pre>
</h:column>
<h:column>
<pre class="dt_row">
#{concordance.right}
</pre>
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
编辑:
我找到了解决方案.<pre>我使用过<code>而不是标记,现在所有数据都完美显示.
我有一项服务,有两个操作.
RegisterUser
UpdateUser
Run Code Online (Sandbox Code Playgroud)
我有一个骆驼溃败:
<camel:route id="myRoute">
<camel:from uri="cxf:bean:myListenerEndpoint?dataFormat=POJO&synchronous=true" />
<camel:bean ref="processor" method="processMessage"/>
<camel:to uri="xslt:file:resources/service/2.0.0/UserRegistration.xsl"/>
<camel:to uri="cxf:bean:myTargetEndpoint"/>
</camel:route>
Run Code Online (Sandbox Code Playgroud)
在我的处理器bean中,当我指定:
RegisterUser registerUser = exchange.getIn().getBody(RegisterUser.class);
Run Code Online (Sandbox Code Playgroud)
我得到了注册用户对象.一切正常.问题是我希望camel有条件地路由我的请求,例如:
如果服务操作是RegisterUser我想将消息路由到我的特定bean,如果服务操作是UpdateUser我想将消息路由到另一个bean.
我曾尝试使用camel xPath,但它似乎没有用.
<camel:route id="myRoute">
<camel:from uri="cxf:bean:myListenerEndpoint?dataFormat=POJO&synchronous=true" />
<camel:choice>
<camel:when>
<camel:xpath>
//RegisterUser
</camel:xpath>
<camel:bean ref="processor" method="processMessage"/>
<camel:to uri="xslt:file:resources/service/2.0.0/UserRegistration.xsl"/>
</camel:when>
</camel:choice>
<camel:to uri="cxf:bean:myTargetEndpoint"/>
</camel:route>
Run Code Online (Sandbox Code Playgroud)
我正在寻找如何设置骆驼路线到不同的目标,但没有找到任何东西.也许有人知道问题出在哪里?
我目前正在使用Dynamics CRM 4.0 Web服务.我做的第一件事是Java/JAX-WS基于webservice的WSDL为wsimport生成正确的类.在生成类时,我遇到了一些错误:
[ERROR] A class/interface with the same name
"com.microsoft.schemas.crm._2007.webservices.RetrieveResponse" is already in use. Use a class customization to resolve this conflict.
line 979 of file://src/main/webapp/WEB-INF/classes/META-INF/wsdl/CrmServiceWsdl.wsdl
[ERROR] (Relevant to above error) another "RetrieveResponse" is generated from here.
line 12274 of file://src/main/webapp/WEB-INF/classes/META-INF/wsdl/CrmServiceWsdl.wsdl
Run Code Online (Sandbox Code Playgroud)
979行告诉我们:
<s:element name="RetrieveResponse">
<s:complexType>
<s:sequence>
<s:element name="RetrieveResult" type="s3:BusinessEntity" />
</s:sequence>
</s:complexType>
</s:element>
Run Code Online (Sandbox Code Playgroud)
第12274行给了我们:
<s:complexType name="RetrieveResponse">
<s:complexContent mixed="false">
<s:extension base="tns:Response">
<s:sequence>
<s:element ref="s3:BusinessEntity" />
</s:sequence>
</s:extension>
</s:complexContent>
</s:complexType>
Run Code Online (Sandbox Code Playgroud)
两个部分都在同一名称空间中.两者都将生成为RetrieveResponse.class,因此它们会发生碰撞.我找到了这个问题的解决方案,即JAX-B绑定xml文件:
<bindings node="//xsd:complexType[@name='RetrieveResponse']">
<jaxb:class name="RetrieveResponseType"/>
</bindings>
Run Code Online (Sandbox Code Playgroud)
这有效(不确定这是否是正确的方法..?)..
所以在此之后,我成功地创建了一些成功的Web服务调用,这很棒! …
我没有做太多反思,所以这个问题可能很明显.例如,我有一个班级:
public class Document {
private String someStr;
private byte[] contents;
//Getters and setters
}
Run Code Online (Sandbox Code Playgroud)
我试图检查该字段contents是否是字节数组的实例.我尝试了什么:
Class clazz = Document.class;
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.getType().isArray()) {
Object array = field.getType();
System.out.println(array);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码的输出是:class [B.我看到找到了字节数组,但如果我这样做:
if (array instanceof byte[]) {...}
Run Code Online (Sandbox Code Playgroud)
这种情况永远不会true.这是为什么?以及如何检查对象是否包含类型为的字段byte[]?
我在Excel文档中使用Apache POI创建了一个LineChart.至于我设法实现的是在下面的图像:

我使用Apache的svn中的示例编写了代码,因此我当前的方法如下所示:
Drawing drawing = question.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 4, 8, 14, 18);
Chart chart = drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
LineChartData data = chart.getChartDataFactory().createLineChartData();
ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
bottomAxis.setCrosses(AxisCrosses.AUTO_ZERO);
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
List<ReportQuestionModel> questionModels = groupModel.getQuestionModels();
for (ReportQuestionModel questionModel : questionModels) {
List<ReportOptionModel> optionModels = questionModel.getOptionModels();
for (ReportOptionModel optionModel : optionModels) {
rowNum++;
XSSFRow optionRow = question.createRow(rowNum);
XSSFCell optionsCell = optionRow.createCell(0);
optionsCell.setCellValue(optionModel.getAnswerText());
long count = optionModel.getCount();
totalResponses += count;
XSSFCell optionsCountCell …Run Code Online (Sandbox Code Playgroud) java ×8
maven ×3
cxf ×2
jaxb ×2
apache-camel ×1
apache-karaf ×1
apache-poi ×1
charts ×1
checkstyle ×1
css ×1
dynamics-crm ×1
excel ×1
html ×1
jax-ws ×1
junit ×1
listener ×1
maven-3 ×1
reflection ×1
routing ×1
spring ×1
wsdl2java ×1
wsimport ×1