Oh duh, I should have seen that coming. Well, now that I'm attempting to
inject TomeeConfiguration in a managed class (annotated @Stateless), I'm
getting this when I attempt to provide that @Resource no matter what
managed class I put it in:
27-Nov-2018 12:57:09.469 SEVERE [localhost-startStop-1]
org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal Unable to
deploy collapsed ear in war
StandardEngine[Catalina].StandardHost[localhost].StandardContext[]
org.apache.openejb.OpenEJBException: Can't find resource for class <<
*Classpath
for class containing @Resource TomeeConfiguration goes here* >>#config. (No
provider available for resource-ref 'null' of type '....*TomeeConfiguration*'
for '<< *Arbitrary class annotated with @Stateless goes here * >>'.)
It looks like the resource that I declared in resources.xml is attempting
to be linked to every managed class when I start TomEE, and something is
failing upon attempting to link the first (arbitrary) one. The arbitrary
managed class that fails has nothing to do with the managed class that
actually contains the @Resource TomeeConfiguration... the injection of
TomeeConfiguration in any managed class is causing this error. I should
note that I don't think the issue is with the @Stateless managed class in
question, which is working properly otherwise.
I've seen this " No provider available for resource-ref 'null' " error in
some googling, but it generally has to do with a library that is either
missing or needs to be put in an exclusions list in /conf, and not project
code itself. I'm not sure what the "null" here is all about, is it
expecting that I put something in /WEB-INF/web.xml ?
Also, the Properties meant to be returned.. is that class
java.util.Properties, or is it supposed to be class
org.apache.openejb.jee.jpa.unit.Properties?
I should also mention, I'm using an exploded WAR deployment.. so I actually
wound up putting resources.xml in WEB-INF.
Thanks again,
-Kean
Post by Romain Manni-Bucau@Resource(name="config")
private TomeeConfiguration config;
In a managed class to inject it. If you do a new tomee does nothing.
Post by Kean EricksonThank you, that sounds like it'll work. I'm finding that getProperties()
on
Post by Kean Ericksonmy configuration file returns null though, I'm wondering if I'm using the
right Properties class (java.util.Properties)?
1. Here's my WEB-INF/resources.xml class (I removed the package name)
--------------------------------------------------------
<Resource id="config" class-name=".....TomeeConfiguration">
UserName = postgres
</Resource>
--------------------------------------------------------
2. Here's my TomeeConfiguration class (taken from the old documentation's
--------------------------------------------------------
package .....;
import java.util.Properties;
public class TomeeConfiguration {
private Properties properties;
public Properties getProperties() {
return properties;
}
public void setProperties(final Properties properties) {
this.properties = properties;
}
}
--------------------------------------------------------
3. Then after the container has been prepared, I try the following, but
c.getProperties() returns null.
--------------------------------------------------------
TomeeConfiguration c = new TomeeConfiguration();
String tomeeUsername = c.getProperties().getProperty("UserName");
--------------------------------------------------------
I'm wondering what I'm missing?
Thanks for your time,
-Kean
On Mon, Nov 26, 2018 at 4:05 AM Jonathan Gallimore <
Post by Jonathan GallimoreHi
Yes - you can also define resources at the application level, by
defining
Post by Kean EricksonPost by Jonathan Gallimoreresources in WEB-INF/resources.xml in your .war file. The syntax is
pretty
Post by Jonathan Gallimoremuch the same as tomee.xml, but with <resources> as the top level tag
as
Post by Kean EricksonPost by Jonathan Gallimoreopposed to <tomee>. The will use the application classpath, eliminating
the
Post by Jonathan Gallimorerequirement to add your resource class to lib/.
Let us know how you get on - if you're stuck, I can dig out an example.
Kind Regards
Jon
On Sun, Nov 25, 2018 at 10:47 PM Romain Manni-Bucau <
Post by Romain Manni-BucauGuess you want to read
http://tomee.apache.org/admin/configuration/index.html - doc is more
complete and up to date.
a
Post by Kean Ericksonresource
Post by Jonathan Gallimorein
Post by Romain Manni-BucauPost by Kean EricksonTomee.xml, under "Custom resources"
http://tomee.apache.org/application-resources.html
..such that I could denote a class-name on the resource pointing
to a
class
Post by Kean Ericksoncase,
Post by Jonathan GallimorePost by Romain Manni-Bucaufor
Post by Kean Ericksonother reasons.. I was wondering if there's any other way to obtain
these
Post by Romain Manni-BucauPost by Kean Ericksonresource properties without having to add anything to TomEE's
classpath.