Hi
Le 1 sept. 2015 04:01, "sgjava" <[email protected]> a écrit :
>
> I have JCache annotations working with a unit test:
>
> KeyValueBean using @CacheDefaults(cacheName = "testCache")
>
> @CacheResult
> public String add(@CacheKey String key, String value) {
> log.info(String.format("Adding key: %s, value: %s", key, value));
> return value;
> }
>
> Test:
>
> /**
> * Injected cache bean.
> */
> @EJB
> private CacheBean cacheBean;
> /**
> * Our key/value bean.
> */
> @EJB
> private KeyValueBean keyValueBean;
>
> container = EJBContainer.createEJBContainer();
> container.getContext().bind("inject", this);
>
> keyValueBean.add("key1", "value1");
>
> INFO: Key: org.jsr107.ri.annotations.DefaultGeneratedCacheKey@322dd1,
Value:
> value1
>
> But using a web test:
>
> final Map p = new HashMap();
> p.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.core.LocalInitialContextFactory");
> p.put("openejb.embedded.initialcontext.close ", "DESTROY");
> p.put("openejb.embedded.remotable", "true");
The 3 previous props are for openejb embedded and not tomee-embedded
> p.put(EJBContainer.APP_NAME, "my-jaxrs-test");
> p.put(EJBContainer.PROVIDER, "tomee-embedded");
> // Add WAR and MDB modules
> p.put(EJBContainer.MODULES, new File[]{Archive.archive().copyTo(
> "WEB-INF/classes", jarLocation(UserService.class)).asDir()});
Dont you miss a beans.xml?
> // Random port
> p.put(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1");
> container = EJBContainer.createEJBContainer(p);
>
> And a service:
>
> /**
> * Injected cache bean.
> */
> @EJB
> private CacheBean cacheBean;
> /**
> * Our key/value bean.
> */
> @EJB
> private KeyValueBean keyValueBean;
>
> The annotations do not work, but I can see cache inside the service class:
>
> log.info(String.format("Cache names: %s",
> cacheBean.getCacheManager().
> getCacheNames()));
>
> INFO: Cache names: [testCache]
>
> Is this a scope or class loader issue with the test container?
>
>
>
>
> --
> View this message in context:
http://tomee-openejb.979440.n4.nabble.com/JCache-annotations-in-web-app-test-tp4676034.html
> Sent from the TomEE Users mailing list archive at Nabble.com.