我正在使用Spring Boot 1.4.1和H2数据库.我通过在application.properties文件中添加以下行来启用H2控制台,如参考指南中所述:
spring.h2.console.enabled=true
spring.h2.console.path=/h2
Run Code Online (Sandbox Code Playgroud)
当我在Chrome 53 for Windows中进入H2控制台时,我可以看到登录页面并单击"测试连接"按钮导致"测试成功":
但是当我点击"连接"按钮时,屏幕变成完全空白.当我查看源代码时,我看到"抱歉,Lynx尚未支持"(请参阅完整源代码).在Firefox中也会发生同样的事情.
为什么会这样?我相信我正在使用正确的JDBC URL,因为有4个不同的人发布了您应该使用的这个问题jdbc:h2:mem:testdb.
我使用此处的说明编写并将CXF Web服务部署到Tomcat服务器.Web服务部署得很好,因为我可以在Web浏览器中看到WSDL文件.
我的独立Java客户端程序不起作用.这是代码:
System.out.println("Creating client");
Properties properties = System.getProperties();
properties.put("org.apache.cxf.stax.allowInsecureParser", "1");
System.setProperties(properties);
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ExampleWebService.class);
factory.setAddress("http://X.X.X.X:9090/WebServices/ExampleWebService");
ExampleWebService exampleWebService = (ExampleWebService)factory.create();
System.out.println("Done creating client");
exampleWebService.method1("test");
System.out.println("After calling method1");
Run Code Online (Sandbox Code Playgroud)
我将所有jar文件(包括woodstox-core-asl-4.2.0.jar文件)从CXF 2.7.7发行版复制到客户端程序的类路径中,当我运行客户端时,我得到以下异常:
Creating client
Nov 20, 2013 8:05:26 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://webservices.server/}ExampleWebServiceService from class server.webservices.ExampleWebService
Done creating client
javax.xml.ws.soap.SOAPFaultException: Cannot create a secure XMLInputFactory
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:157)
at $Proxy38.printString(Unknown Source)
at ExampleNmsWebServiceClient.printString(ExampleNmsWebServiceClient.java:29)
at ExampleNmsWebServiceClient.main(ExampleNmsWebServiceClient.java:40)
Caused by: org.apache.cxf.binding.soap.SoapFault: Cannot create a secure XMLInputFactory
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:84)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:51) …Run Code Online (Sandbox Code Playgroud) 我已经按照这里描述的"测试Spring MVC切片"部分为Spring MVC控制器编写了一个测试类.这个类看起来像这样:
@RunWith(SpringRunner.class)
@WebMvcTest(controllers=OurController.class)
public class OurControllerTest {
@Autowired
private MockMvc mvc;
@MockBean
private OurRepository ourRepository;
@Test
public void testGetStuff() {
// code removed
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到以下错误:
MockHttpServletResponse:
Status = 401
Error message = null
Headers = {Cache-Control=[no-store], Pragma=[no-cache], WWW-Authenticate=[Bearer realm="oauth2-resource", error="unauthorized", error_description="Full authentication is required to access this resource"], Content-Type=[application/json;charset=UTF-8], X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], X-Frame-Options=[DENY]}
Content type = application/json;charset=UTF-8
Body = {"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
Forwarded URL = null
Redirected URL = null …Run Code Online (Sandbox Code Playgroud) 在我的hibernate.cfg.xml中,我有以下内容:
<property name="show_sql">true</property>
Run Code Online (Sandbox Code Playgroud)
在我的log4j.xml中,我有以下内容:
<logger name="org.hibernate" additivity="false">
<level value="TRACE"/>
<appender-ref ref="hbn_log"/>
</logger>
<category name="org.hibernate.SQL" additivity="false">
<priority value="TRACE"/>
<appender-ref ref="hbn_log"/>
</category>
<category name="org.hibernate.type" additivity="false">
<priority value="TRACE"/>
<appender-ref ref="hbn_log"/>
</category>
<logger name="org.hibernate.type.descriptor.sql.BasicBinder">
<level value="TRACE"/>
<appender-ref ref="hbn_log"/>
</logger>
<logger name="org.hibernate.event.def.DefaultLoadEventListener" additivity="true">
<level value="all"/>
<appender-ref ref="hbn_log"/>
</logger>
<logger name="org.hibernate.cache.ReadWriteCache" additivity="true">
<level value="all"/>
<appender-ref ref="hbn_log"/>
</logger>
<appender name="hbn_log" class="com.adventnet.management.log.NMSRollingFileAppender">
<param name="File" value="logs/hbn.txt"/>
<param name="MaxFileSize" value="1MB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd MMM yyyy HH:mm:ss:SSS}] %-5c{2}: %m%n"/>
</layout>
<param name="Threshold" value="TRACE"/>
</appender>
Run Code Online (Sandbox Code Playgroud)
在我的stdout.txt中,我可以看到它记录了SQL语句:
[13 …Run Code Online (Sandbox Code Playgroud) StackOverflow 上的一个答案- debug: var=vars建议使用或- debug: var=hostvars打印出 Ansible playbook 使用的所有变量。
使用var=hostvars并没有打印出所有变量。但是,当我将以下行添加到我的剧本执行的角色的 main.yml 文件顶部时,我确实打印出了所有变量:
- name: print all variables
debug:
var=vars
Run Code Online (Sandbox Code Playgroud)
问题在于,如果打印出来的变量值依赖于其他变量的值,则这些值不会被完全评估。例如,以下是打印出来的部分内容:
"env": "dev",
"rpm_repo": "project-subproject-rpm-{{env}}",
"index_prefix": "project{{ ('') if (env=='prod') else ('_' + env) }}",
"our_server": "{{ ('0.0.0.0') if (env=='dev') else ('192.168.100.200:9997') }}",
Run Code Online (Sandbox Code Playgroud)
我怎样才能让 Ansible 打印出像这样完全评估的变量?
"env": "dev",
"rpm_repo": "project-subproject-rpm-dev",
"index_prefix": "project_dev",
"our_server": "0.0.0.0",
Run Code Online (Sandbox Code Playgroud)
编辑:
将答案tasks中的部分合并到我的剧本文件中并删除该部分后,我的剧本文件如下所示(其中包含一些变量定义):rolesinstall-vars.yml
- hosts: all
become: true
vars_files:
- install-vars.yml
tasks:
- debug:
msg: |-
{% …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下Java代码来压缩和解压缩String.但是,从新的ByteArrayInputStream对象创建新GZipInputStream对象的行会抛出"java.util.zip.ZipException:Not in GZIP format"异常.有谁知道如何解决这个问题?
String orig = ".............";
// compress it
ByteArrayOutputStream baostream = new ByteArrayOutputStream();
OutputStream outStream = new GZIPOutputStream(baostream);
outStream.write(orig.getBytes());
outStream.close();
String compressedStr = baostream.toString();
// uncompress it
InputStream inStream = new GZIPInputStream(new ByteArrayInputStream(compressedStr.getBytes()));
ByteArrayOutputStream baoStream2 = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int len;
while((len = inStream.read(buffer))>0)
baoStream2.write(buffer, 0, len);
String uncompressedStr = baoStream2.toString();
Run Code Online (Sandbox Code Playgroud) Jackson有@JsonProperty("name")注释,可以应用于方法 - 方法的返回值将被分配给JSON中的"name"参数.
我发现Gson有@SerializedName注释,但不能与方法一起使用.有没有办法在Gson中获取方法的@JsonProperty功能?
假设我有以下课程:
public class MyClass {
private Test t;
public MyClass() {
t = new Test(50);
}
}
public class Test {
private int test;
public Test(int test) {
this.test = test;
}
public String toCustomString() {
return test + "." + test;
}
}
Run Code Online (Sandbox Code Playgroud)
当Jackson序列化一个实例时MyClass,它将如下所示:
{"t":{"test":50}}
我是否可以在Test类中添加注释以强制Jackson toCustomString()在序列化Test对象时调用该方法?
当Jackson序列化一个实例时,我想看到以下输出之一MyClass:
{"t":"50.50"}
{"t":{"test":"50.50"}}
我正在对Swing应用程序进行增强(以前从未完成过Swing编程),并且需要能够以JList粗体显示单个文本项.我已经看到了一些帖子,他们说只是把"<html><b>"和"</b></html>"串绕.你是认真的,这似乎是一个黑客.将来我们也可能想要更改JList中项目的背景颜色 - HTML标签也可以吗?
我见过的另一个建议是setCellRenderer()用你自己的实现ListCellRenderer接口的对象调用JList上的方法.但我不确定能做到我们想要的.似乎ListCellRenderer有一种getListCellRendererComponent()方法可以设置项目的显示方式,具体取决于项目是选中还是具有焦点.但是我们希望JList中的一个项目是粗体,具体取决于我们的业务逻辑确定的内容,并且它可能是既未选择也没有焦点的项目.我没有看到任何这方面的好例子ListCellRenderer,所以我不确定这是否是我们想要的方法.
我正在使用Gson将java.util.Date对象转换为Json,然后将Json转换回java.util.Date对象:
Date date = new Date();
System.out.println("date=" + date + "; date.getTime()=" + date.getTime());
String json = gson.toJson(date);
System.out.println("date in json format=" + json);
Date newDate = gson.fromJson(json, Date.class);
System.out.println("newDate=" + newDate + "; gettime=" + date.getTime());
if (!newDate.equals(date)) {
System.out.println("dates are not the same - bad");
}
else
System.out.println("dates are the same - good");
Run Code Online (Sandbox Code Playgroud)
2 Date对象应该相等,但从输出中可以看出,它们不是:
date=Fri Nov 23 12:18:21 EST 2012; date.getTime()=1353691101023
date in json format="Nov 23, 2012 12:18:21 PM"
newDate=Fri Nov 23 12:18:21 EST 2012; gettime=1353691101023
dates …Run Code Online (Sandbox Code Playgroud) java ×6
jackson ×2
json ×2
spring-boot ×2
ansible ×1
compression ×1
cxf ×1
date ×1
gson ×1
gzip ×1
h2 ×1
hibernate ×1
jlist ×1
logging ×1
parameters ×1
spring-mvc ×1
sql ×1
swing ×1
testing ×1
unit-testing ×1
variables ×1
web-services ×1
woodstox ×1