尝试在tomee.xml中添加"java.net.URL"资源,但参数没有传递给构造函数。以下是对 tomee .xml 的补充:
<Resource id="someJndiName" class-name="java.net.URL" factory-name="URL" constructor="spec">
spec http://google.com
</Resource>
这会导致:
INFO: Creating Resource(id=someJndiName)
Dec 18, 2013 5:10:12 AM org.apache.openejb.util.OpenEJBErrorHandler handleUnknownError
SEVERE: FATAL ERROR: Unknown error in Assembler. Please send the following stack trace and this message to users@openejb.apache.org :
java.lang.NullPointerException
at org.apache.xbean.recipe.ReflectionUtil.toParameterList(ReflectionUtil.java:1026)
at org.apache.xbean.recipe.ReflectionUtil.findStaticFactory(ReflectionUtil.java:811)
at org.apache.xbean.recipe.ObjectRecipe.findFactory(ObjectRecipe.java:538)
at org.apache.xbean.recipe.ObjectRecipe.internalCreate(ObjectRecipe.java:274)
at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:96)
基于 OpenEJB/TomEE 资源:它是如何工作的? 代码使用反射来调用构造函数,并且应该传递参数,但这里似乎不是这种情况。这是一个错误,还是有另一种方法可以将参数传递给构造函数?
我尝试在"%TomEE%/conf/system.properties"中添加一个条目,但它没有改变。
someJndiName.spec=http://google.com
我尝试对 URL 使用 3 参数构造函数,结果相同。
<Resource id="someJndiName" class-name="java.net.URL" factory-name="URL" constructor="protocol, host, file">
protocol http
host google.com
file
</Resource>
我目前的需求是将"java.net.URL"对象添加到服务器资源中,但是能够使用这种通用方法添加任意对象将非常有用。
是否需要为"java.net.URL"创建一些处理程序类才能作为TomEE资源进行处理?
你还有这个问题吗?这在 TomEE 7.1.0 中工作。
resources.xml
:
<resources>
<Resource id="myURL"
class-name="java.net.URL"
constructor="spec">
spec http://google.com
</Resource>
</resources>
Application.java
:
package com.test.application;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Startup;
import javax.enterprise.context.ApplicationScoped;
import java.net.URL;
@Slf4j
@Startup
@ApplicationScoped
public class Application {
@Resource(name = "myURL")
private URL url;
@PostConstruct
private void init() {
log.info("URL={}", url);
}
}