我有一个使用默认命名空间打印的文件.这些元素使用前缀ns2打印,我需要将其删除,我的代码如何:
<ns2:foo xmlns:ns2="http://namespace" />
Run Code Online (Sandbox Code Playgroud)
我希望如何:
<foo xmlns="http://namespace" />
Run Code Online (Sandbox Code Playgroud)
这就是我编写它的方式,正如我所看到的那样,ns2应该足够了:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:bar="http://namespace" targetNamespace="http://namespace"
elementFormDefault="qualified">
...
Run Code Online (Sandbox Code Playgroud)
生成的package-info结果如下:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://namespace",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.foo.bar;
Run Code Online (Sandbox Code Playgroud)
我创建这样的文件:
JAXBContext jaxbContext = JAXBContext.newInstance(generatedClassesPackage);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(new JAXBElement<Foo>(new QName("http://namespace", "Foo"),
Foo.class, rootFoo), outputStream);
Run Code Online (Sandbox Code Playgroud)
generatedClassesPackage是package-info.java和元素所在的包.
Foo对象已定义,并具有以下元素::
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"group"
})
@XmlRootElement(name = "Foo")
public class Foo {
@XmlElement(name = "Group", required = true)
protected List<Group> group;
Run Code Online (Sandbox Code Playgroud)
这是我错过的东西吗?或者我误解了它是如何工作的?
在我参与的许多项目中,我们经常会有很多类将内容从一个域模型映射到另一个域模型.例如,从WSDL生成的模型到项目特定的模型.
例如
public class FooBarContentMapper {
public static Foo fromWsToDomain(FooType fooType) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
这也可以是一个非静态方法,服务层可以有一个映射器对象字段,而不是调用静态方法:
public class FooBarContentMapper {
public Foo fromWsToDomain(FooType fooType) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我发现两种方式都使用了很多,但是:
我有使用自定义javaTypes的WSDL的问题,其中有几个模式.绑定适用于具有给定命名空间的模式,但是对于没有命名空间的模式,编译失败.
这是bindings.xml文件:
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:common="urn:my:ns">
<jaxb:globalBindings generateElementProperty="false">
<jaxb:serializable uid="1"/>
<jaxb:javaType name="java.util.Date" xmlType="xs:date"
parseMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.parseDate"
printMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.printDate"/>
<jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/>
<jaxb:javaType name="java.util.UUID" xmlType="common:uuid"
parseMethod="my.package.UuidConverter.parse"
printMethod="my.package.UuidConverter.print"/>
</jaxb:globalBindings>
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)
我正在使用cxf-codegen-plugin
错误消息是:undefined simple type
当urn:my:ns不存在于其中一个模式中时,是否可以忽略UUID绑定?或者是否可以使用不同的方法归档此绑定?
我有一些代码在协程的函数调用中使用请求范围的 bean。似乎春天不知道我还在同一个请求中。
即使调用来自异步 Kotlin 协程,是否有可能让 spring 理解我仍然想要请求范围的 bean?
代码运行时我收到此错误消息:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'scopedTarget.wsContext':
Scope 'request' is not active for the current thread;
consider defining a scoped proxy for this bean if you intend to refer to it from a singleton;
nested exception is java.lang.IllegalStateException:
No thread-bound request found:
Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread?
If you are actually operating within a …Run Code Online (Sandbox Code Playgroud) 我已经定义了以下事务管理器:
<tx:annotation-driven transaction-manager="txManager" mode="aspectj" />
Run Code Online (Sandbox Code Playgroud)
并具有以下根元素:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
Run Code Online (Sandbox Code Playgroud)
一切正常,但IntelliJ在mode ="aspectj"上给我一个错误标记, 说不允许.我已经跟随它获取xsd的位置,它链接到tx 2.0 xsd - 这解释了错误消息,因为我需要2.5来使用模式注释.
有可能以某种方式给IntelliJ一个提示,我应该向2.5而不是2.0验证?
在 intelliJ 中,我收到以下代码的错误消息“EL out of attribute”:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<h1>JSF and Spring</h1>
#{helloBean.hello()}
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
显然这是 EL 扩展的非标准用法,但我很难理解我应该如何做到这一点。我的代码工作得很好,但我喜欢使用“正确”的方式,IntelliJ 中的警告可能意味着我遗漏了一些东西。
我应该如何将其编写为“正确”的 JSF 2?

