当JAXB将日期对象(XMLGregorianCalendar
)编组到xsd:dateTime元素中时,如何指定生成的XML的格式?
例如:默认数据格式是使用<StartDate>2012-08-21T13:21:58.000Z</StartDate>
我需要的毫秒来省略毫秒. <StartDate>2012-08-21T13:21:58Z</StartDate>
如何指定我希望它使用的输出格式/日期格式?我正在使用javax.xml.datatype.DatatypeFactory
创建XMLGregorianCalendar
对象.
XMLGregorianCalendar xmlCal = datatypeFactory.newXMLGregorianCalendar(cal);
Run Code Online (Sandbox Code Playgroud) 是否有用于编辑java类文件的实用程序(或eclipse插件)?我想操纵java类文件的字节码而不重新编译它,也没有完整的构建路径.
例如,重命名方法,添加/删除指令,更改常量等.
我找到的唯一工具是:
我想使用spring-test配置内部类(@Configuration
)配置组件测试.经过测试的组件有一些我想模拟测试的服务.这些服务是类(没有使用接口)并且@Autowired
在其中具有spring注释().Mockito可以很容易地模仿它们,但是,我发现无法禁用弹簧自动装配.
我可以轻松重现的示例:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SomeTest.Beans.class)
public class SomeTest {
// configured in component-config.xml, using ThirdPartyService
@Autowired
private TestedBean entryPoint;
@Test
public void test() {
}
@Configuration
@ImportResource("/spring/component-config.xml")
static class Beans {
@Bean
ThirdPartyService createThirdPartyService() {
return mock(ThirdPartyService.class);
}
}
}
public class ThirdPartyService {
@Autowired
Foo bar;
}
public class TestedBean {
@Autowired
private ThirdPartyService service;
}
Run Code Online (Sandbox Code Playgroud)
在此示例中,"TestBean"表示要模拟的服务.我不希望春天注入"酒吧"!@Bean(autowire = NO)
没有帮助(事实上,这是默认值).(请保存我从"使用界面!"评论 - 模拟服务可以是第三方,我无法做任何事情.)
UPDATE
Springockito部分解决了这个问题,只要你没有其他任何东西可以配置(所以你不能使用Springockito的配置类 - 它不支持它),但只使用模拟.还在寻找纯弹簧解决方案,如果有的话...
我已经创建了演示Spring Boot项目并实现了Restful服务,如下所示
@RestController
public class GreetingsController {
@RequestMapping(value="/api/greetings", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getGreetings(){
return new ResponseEntity<String>("Hello World", HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用Postman工具调用带有URL" http:// localhost:8080/api/greetings "作为请求方法GET的服务时,我收到以下错误消息
{
"timestamp": 1449495844177,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/api/greetings"
}
Run Code Online (Sandbox Code Playgroud)
Per Spring Boot应用程序,我不必在web.xml中配置Spring Dispatcher servlet.
有人可以帮我找出这里遗漏的地方吗?
我在一个多月后面临这个问题,这是我在命令行上运行java时看到的:
$ java -Xmx1300m
Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.
Run Code Online (Sandbox Code Playgroud)
如果我运行较少的内存它工作正常
$ java -Xmx1240m Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) ..... .....
Run Code Online (Sandbox Code Playgroud)
我花了一个星期试图调试这个没什么用.最后我让我的IT支持人员更换笔记本电脑.这发生在一个月前的10月23日.现在,一个月后,我的新系统又出现了同样的问题.
我的系统配置是:
Win 7 Enterprise(64位),Service Pack 1.英特尔(R)Core(TM)i7-2640M CPU @ 2.80GHz 8.00 GB RAM
Java: java version "1.5.0_20" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_20-b02) Java HotSpot(TM) Client VM …
Run Code Online (Sandbox Code Playgroud) 我正在使用ant wsimport从wsdls生成客户端存根.另外,我想生成实现的客户端类Serializable
.我想serialVersionUID
为每个班级生成一个不同的.我尝试使用下面显示的绑定文件.但它serialVersionUID
为所有类生成相同.有什么方法可以把我自己serialVersionUID
的每个班级都给自己?
<wsimport xendorsed="true" binding="binding.xml" debug="true" keep="true"
verbose="false" sourcedestdir="${generated}" wsdl="${src}${wsdl.file}"
wsdlLocation="${wsdl.file}">
</wsimport>
Run Code Online (Sandbox Code Playgroud)
绑定配置
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalBindings>
<serializable uid="1" />
</globalBindings>
</bindings>
Run Code Online (Sandbox Code Playgroud) 我正在使用 REST 模板故意在请求 uri 中发送一个 %,例如 /items/a%b
String responseEntity = restTemplate.exchange("/items/a%b",
requestObj.getHttpMethod(), requestEntity, String.class);
Run Code Online (Sandbox Code Playgroud)
将restTemplate
被转换此URI的endoding,它正在成为/items/a%25b
这有意义的,因为在默认情况下,其余模板编码的URI。
我尝试UriComponent
用于禁用 uri 的编码
UriComponents uriComponents = UriComponentsBuilder.fromPath("/items/a%b").build();
URI uri= uriComponents.toUri();
String responseEntity = restTemplate.exchange(uri,
requestObj.getHttpMethod(), requestEntity, String.class);
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为 uri 再次是进行编码的 URI 类型。我确定我没有以正确的方式使用 UriComponents。
如果有人能指出禁用编码的正确方法,我将不胜感激。
谢谢。
我正在尝试解组XML文件.我创建了Jaxb类但是当我尝试解组时,它给了我:
Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"processedSalesOrderTypeList"). Expected elements are <{api.supplieroasis.com}processedSalesOrderMessage>,<{api.supplieroasis.com}salesOrderMessage>,<{api.supplieroasis.com}shipperOfRecordAccountNumber>,<{api.supplieroasis.com}shippingAccountNumber>,<{api.supplieroasis.com}uspsMailerId>,<{api.supplieroasis.com}warehouseName>
Run Code Online (Sandbox Code Playgroud)
这是我的ObjectFactory.java类:
@XmlRegistry
public class ObjectFactory {
private final static QName _ProcessedSalesOrderMessage_QNAME = new QName("api.supplieroasis.com", "processedSalesOrderMessage");
private final static QName _WarehouseName_QNAME = new QName("api.supplieroasis.com", "warehouseName");
private final static QName _ShippingAccountNumber_QNAME = new QName("api.supplieroasis.com", "shippingAccountNumber");
private final static QName _ShipperOfRecordAccountNumber_QNAME = new QName("api.supplieroasis.com", "shipperOfRecordAccountNumber");
private final static QName _SalesOrderMessage_QNAME = new QName("api.supplieroasis.com", "salesOrderMessage");
private final static QName _UspsMailerId_QNAME = new QName("api.supplieroasis.com", "uspsMailerId");
}
Run Code Online (Sandbox Code Playgroud)
XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="api.example.com" …
Run Code Online (Sandbox Code Playgroud)I'm migrating to spring security 4.0.1 using java config instead of xml. When I autowire PasswordEncoder
, it gives me the following error:
HTTP Status 500 - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.UsersComponent': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.crypto.password.PasswordEncoder com.car.component.impl.UsersComponentImpl.passwordEncoder; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.crypto.password.PasswordEncoder] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
我将发布我的所有配置文件.我不知道我哪里错了. …
java ×8
spring ×4
jaxb ×3
spring-mvc ×2
.class-file ×1
bytecode ×1
dao ×1
datetime ×1
decompiler ×1
format ×1
junit ×1
marshalling ×1
memory ×1
milliseconds ×1
mockito ×1
rest ×1
resttemplate ×1
spring-boot ×1
spring-test ×1
wsimport ×1
xjc ×1
xml ×1
xsd ×1