我有可以以各种格式保存文件的应用程序(所有格式都是 xml)。所以我应该解决确定保存的格式文件的问题。所以,我看到了 2 个解决方案
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "bla-bla.xsd");
所以我想我可以使用它 unmarshaller.getProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION)
但它扔
javax.xml.bind.PropertyException: jaxb.noNamespaceSchemaLocation
并getSchema() 返回 null 那么,如何获取架构位置?
setAdapter(Class<A> type, A adapter)方法为不同的bean指定不同的适配器 哪种方式更可取?如果首先,那么我怎样才能获得架构位置标签?
更新代码示例 假设我们有 bean
@XmlRootElement
public class Foo{
String bar;
public String getBar() {return bar; }
public void setBar(String bar) {this.bar = bar;}
}
Run Code Online (Sandbox Code Playgroud)
和生成模式的代码,然后保存 Foo 的实例并加载。
public class Test {
final static String schemaLoc = "fooschema.xsd";
public static void write(File file, Foo foo, Schema schema) throws Throwable {
XMLEventWriter xsw = null; …Run Code Online (Sandbox Code Playgroud) 我有带依赖关系的MethodInterceptor.我怎么能注射它们?
在这里,2007年,Bob Lee说这种可能性应该包含在下一个版本中,但是我找不到这个API.
bindInterceptor方法需要实例而不是类.
我想在我编组的每个xml文件中定义模式.然后在解组过程中获取此模式(路径字符串).marshaller.setSchema()只要
允许调用者在编组时验证编组的XML.
是的,我可以为此目的编写额外的bean,但我希望得到xml之类的
<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='bla-bla.xsd'>...
Run Code Online (Sandbox Code Playgroud) 我正在学习java.util.concurrent库,并在源代码中找到许多无限循环,就像这个
//java.util.concurrent.atomic.AtomicInteger by Doug Lea
public final int getAndSet(int newValue) {
for (;;) {
int current = get();
if (compareAndSet(current, newValue))
return current;
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道,在什么情况下实际值不能等于预期值(在这种情况下compareAndSet返回false)?
上周我发现了Guice ...我正在尝试一些简单的技巧.但是,我目前被封锁......
我正在尝试将请求转发到由包含" * " 的url-pattern服务的Servlet中的JSP .但我一直收到"错误404":(
一步步 :
ServletModule :
serve("/test/*").with(TestServlet.class);
Run Code Online (Sandbox Code Playgroud)
TestServlet :
public void doGet(HttpServletRequest req, HttpServletResponse resp)
{
System.err.println("Start");
try
{
req.getRequestDispatcher("/WEB-INF/layout/test.jsp").forward(req, resp);
}
catch (Exception e)
{
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
HTTP错误404
访问/WEB-INF/layout/test.jsp时出现问题.原因:/
WEB-INF/layout/test.jsp
我测试了"serve("/ test").with(TestServlet.class);" 它工作
我没有Guice测试(通过在web.xml中定义servlet),它工作...
感谢阅读!
我有2个组件A和B.A取决于B.我写了类似的东西:
public class A {
private B b;
@Autowired
public void setB(B b) {
this.b = b;
}
}
@Component
public class B {}
new XmlBeanFactory(new FileSystemResource("./spring.xml")).getBean(A.class);
Run Code Online (Sandbox Code Playgroud)
配置
<context:annotation-config/>
<context:component-scan
base-package="com">
</context:component-scan>
<bean class="com.A" autowire="byType" />
Run Code Online (Sandbox Code Playgroud)
它工作得很好.现在我也希望A通过注释进行配置.所以我添加了@Component注释A
@Component
public class A {
private B b;
@Autowired
public void setB(B b) {
this.b = b;
}
}
Run Code Online (Sandbox Code Playgroud)
并A从配置中删除了说明.所以它只是
<context:annotation-config/>
<context:component-scan
base-package="com">
</context:component-scan>
Run Code Online (Sandbox Code Playgroud)
但是B不再注射了.可能我应该指定自动装配类型或像这样的smt.那么我该如何解决呢?
我才开始学习番石榴.所以我不知道最佳实践等等.这些是代码(它绑定了一些类,并按输入集合放入顺序):
public ImmutableList<ModelBean> toBean(Collection<Shape> model) {
return ImmutableList.copyOf(Collections2.transform(Ordering.from(new Comparator<Shape>() {
@Override
public int compare(Shape o1, Shape o2) {
return 0; //here placed some one line logic
}
}).sortedCopy(model), new Function<Shape, ModelBean>() {
final ModelBeanCreator binder = new ModelBeanCreator();
@Override
public ModelBean apply(Shape input) {
return binder.createModelBean(input);
}
}));
}
Run Code Online (Sandbox Code Playgroud)
那么,我应该在几个操作中将它分开吗?
更新 它做什么?它需要收集.对它进行排序.将每个对象映射到另一个对象.创建新的ImmutableList并返回它.
开发和生产环境之间的GAE/J关键差异是什么?
java google-app-engine development-environment production-environment
我喜欢番石榴的前提条件,但我真正需要的是另外一种方法 - 检查数字是否在范围内.像这样的Smt
//probably there should be checkStateInRange also
public static void checkArgumentInRange(double value, int min, int max) {
if (value < min || value > max) {
throw new IllegalArgumentException(String.format("%s must be in range [%s, %s]", value, min, max));
}
}
Run Code Online (Sandbox Code Playgroud)
我相信我并不孤单,这是一个很常见的情况.但这种方法不存在.有没有理由不把这些方法放进去com.google.common.base.Preconditions?
Scala具有可变类Array.它有方法sorted,reverse并且它们以某种顺序返回具有相同项目的新可变数组.
是否有某些理由为方法名称设置不同的形式?为什么sorted没有命名sort?为什么reverse,sortBy等没有命名reversed,sortedBy?