小编Xst*_*ian的帖子

如何指定JAXB封送xsd:dateTime时使用的日期格式?

当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)

format datetime jaxb marshalling milliseconds

83
推荐指数
2
解决办法
8万
查看次数

DAO和DAL有什么区别?

在学校学习Java后,我对DAO模式(数据访问对象)非常熟悉.但是在工作中我使用.NET.在.NET中,经常有关于DAL(数据访问层)的讨论.对我来说,他们的目的似乎很相似.所以问题是DAO和DAL基本相同吗?DAL这个术语是否只是组成,所以它不会与数据访问对象混淆?

dao data-access-layer data-access-object

46
推荐指数
2
解决办法
3万
查看次数

是否有java类文件/字节码编辑器来编辑指令?

是否有用于编辑java类文件的实用程序(或eclipse插件)?我想操纵java类文件的字节码而不重新编译它,也没有完整的构建路径.

例如,重命名方法,添加/删除指令,更改常量等.

我找到的唯一工具是:

  • 类编辑 ,但它在功能上非常有限的(如物联网和操作说明改名是不可能的).

  • jbe不保存更改(可能因为类验证失败 - 在我进行任何更改之前,尽管类运行完美)

    (jbe最初有一个类路径问题,将jbe.bat文件的类路径添加到了帮助中)

java bytecode bytecode-manipulation decompiler .class-file

30
推荐指数
3
解决办法
2万
查看次数

如何在@ Configuration/@ Bean使用的单元测试中禁用Spring自动装配

我想使用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的配置类 - 它不支持它),但只使用模拟.还在寻找纯弹簧解决方案,如果有的话...

java junit spring spring-test mockito

16
推荐指数
3
解决办法
1万
查看次数

使用Spring Boot + REST应用程序获取"无消息可用"错误

我已经创建了演示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 rest spring spring-mvc spring-boot

15
推荐指数
4
解决办法
4万
查看次数

初始化VM时出错无法为对象堆保留足够的空间无法创建Java虚拟机

我在一个多月后面临这个问题,这是我在命令行上运行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)

java memory

11
推荐指数
3
解决办法
10万
查看次数

为JAXB中的每个生成的类生成唯一的可序列化id

我正在使用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)

java serialization jaxb xjc wsimport

11
推荐指数
1
解决办法
4834
查看次数

如何使用 RestTemplate 禁用编码

我正在使用 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。

如果有人能指出禁用编码的正确方法,我将不胜感激。

谢谢。

java spring spring-mvc resttemplate

10
推荐指数
2
解决办法
8334
查看次数

Jaxb UnMarshal错误:意外元素(uri:"",local:"processedSalesOrderTypeList").预期的要素是

我正在尝试解组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)

java xml xsd jaxb unmarshalling

9
推荐指数
2
解决办法
993
查看次数

Could not autowire field:private org.springframework.security.crypto.password.PasswordEncoder;

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 spring spring-security

8
推荐指数
2
解决办法
1万
查看次数