我有一些代码使用JAXB API类,它们是作为Java 6/7/8中JDK的一部分提供的.当我使用Java 9运行相同的代码时,在运行时我得到错误,指示无法找到JAXB类.
自Java 6以来,JAXB类已作为JDK的一部分提供,为什么Java 9不再能够找到这些类?
获得具有List类型字段的实体的最智能方法是什么?
package persistlistofstring;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Persistence;
@Entity
public class Command implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@Basic
List<String> arguments = new ArrayList<String>();
public static void main(String[] args) {
Command command = new Command();
EntityManager em = Persistence
.createEntityManagerFactory("pu")
.createEntityManager();
em.getTransaction().begin();
em.persist(command);
em.getTransaction().commit();
em.close();
System.out.println("Persisted with id=" + command.id);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码生成:
> Exception in thread "main" javax.persistence.PersistenceException: No Persistence …Run Code Online (Sandbox Code Playgroud) 我是Angular2的新手.我的项目的技术堆栈是Angular2,其中包含typescript和spring作为后端.我不想按照指示使用节点服务器来编译我的前端,但我需要使用TOMCAT和Maven.我有几个问题.
任何人都可以给我一步一步的指导来创建一个Angular2 + Spring应用程序,使用'bower或任何其他工具进行前端任务管理,例如缩小文件,创建应用程序支架'和'Maven for backend task management'?我愿意接受任何建议.
我有一个文本使用百里香叶呈现三种不同的颜色.
所以我到目前为止测试该值的代码是:
th:if="${evaluation} > 50"
th:if="${evaluation} < 30"
Run Code Online (Sandbox Code Playgroud)
这很有效.
但第三个测试是针对这两者之间的值.所以我尝试过:
th:if="(${evaluation} < 49) ∧ (${evaluation} > 29)"
Run Code Online (Sandbox Code Playgroud)
但是它不起作用,我在解析时遇到了这个错误:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "(${evaluation} < 49) ∧ (${evaluation} > 29)" (/property.html:41)
Run Code Online (Sandbox Code Playgroud)
当然,这些行在标签之间,因为前两个正常工作.
也许操作数和操作数不正确,但百里香叶的文档并没有真正明确这些操作数.
欢迎所有想法!
更新:我从百万富翁论坛得到了答案.做到这一点的方法是:
th:if="${evaluation < 49 and evaluation > 29}"
Run Code Online (Sandbox Code Playgroud)
问题解决了!
我有一个命令行工具,我想从java应用程序启动.然后我的应用程序应该等待命令行工具返回/完成.我将在Windows,Mac和Linux上部署我的应用程序,我的应用程序应该能够在每个平台上调用命令行工具.如何从我的java应用程序中正确调用它?
请考虑以下代码:
public void broadcast(FacesEvent event)
throws AbortProcessingException {
if(!(event instanceof WrapperEvent)) {
super.broadcast(event);
return;
}
// Sets up the correct context and fire our wrapped event.
GridWrapperEvent revent = (GridWrapperEvent)event; // FindBugs is complaining here
int oldRowIndex = getRowIndex();
int oldColumnIndex = getColumnIndex();
boolean oldClientIdRewritting = clientIdRewritting;
setClientIdRewritting(revent.isClientIdRewritting());
setActiveCell(revent.getRowIndex(), revent.getColumnIndex());
FacesEvent rowEvent = revent.getFacesEvent();
rowEvent.getComponent().broadcast(rowEvent);
setActiveCell(oldRowIndex, oldColumnIndex);
setClientIdRewritting(oldClientIdRewritting);
}
Run Code Online (Sandbox Code Playgroud)
FindBugs抱怨注释行.我能做些什么吗?这就是FindBugs所说的:
未选中/未确认的 强制转换此未强制转换,并非所有类型的实例都可以强制转换为其强制类型.确保您的程序逻辑确保此强制转换不会失败.
我目前正在使用gdb调试程序.我必须一遍又一遍地启动gdb并执行相同的步骤:
设置断点,运行,打印变量,退出
有没有办法让gdb自动为我做这件事?可能是一个可以作为参数附加的脚本?
提前致谢!
我正在使用 Apache camel 将一些 SOAP 消息从 A 路由到 B。
我想为某些特定路由添加日志记录,但问题是消息正文是一个流。
我的解决方案是将该流转换为字符串,然后将其发送到端点 B。
这似乎工作正常,但我不确定这种方法有多干净?
这是我的路线现在的样子:
<route>
<from uri="cxf:bean:ServiceA?dataFormat=MESSAGE" />
<convertBodyTo type="java.lang.String"/>
<to uri="log:my.company?level=WARN"/>
<to ref="ServiceB" />
</route>
Run Code Online (Sandbox Code Playgroud)
问题是我是否应该使用 WireTap 和流缓存来复制流,将其转换为字符串,记录它并将另一个未触及的流发送到 ServiceB。我找不到正确执行此操作的方法。这是我这样做的尝试:
<route streamCache="true">
<from uri="cxf:bean:ServiceA?dataFormat=MESSAGE" />
<wireTap uri="log:my.company?level=WARN" /> <!-- how to convert this stream to a string? -->
<to ref="ServiceB" />
</route>
Run Code Online (Sandbox Code Playgroud)
你认为呢?WireTap还是上面的解决方案?