我試圖停用使用試圖停用狀態會話bean的鈍化與@CacheConfig
@CacheConfig(MAXSIZE = 0,idleTimeoutSeconds = 0)一狀態會話bean的鈍化
http://docs.jboss.org/ejb3/docs/reference/1.0.7/html/SessionBean_and_MDB_configuration.html
我向有狀態會話bean和它注入的託管bean添加了一些print語句,以更好地理解發生了什麼。看起來,有狀態bean確實被注入到託管bean中(因爲它不是null),但調用它的方法沒有任何作用(如果您查看下面託管bean的loadData()方法,它會調用test()例程的有狀態會話bean,但輸出「test」從不出現)。
15:06:07861 INFO [STDOUT] loadData programSlug =一些-程序名
15:06:07876 INFO [STDOUT] programServiceBean =否接口視圖端點[jboss.j2ee:罐= TEI.war,名字= ProgramServiceBean,服務= EJB3]和會話43h1h2v-j35uon-h18czgvf -1- h18d0nzj-DF
15:06:07908 ERROR [org.apache.catalina.core.ContainerBase [JBoss的。 Servlet.service()用於servlet Faces Servlet拋出異常:java.lang.IllegalStateException: 無法找到成員[com.ray.TEI.model.Program #urlSlug] at org.hibernate.ejb.metamodel.AbstractAttribute.readObject(AbstractAttribute.java:122)[:3.6.6.Final] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_30] at sun .reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39):1.6.0_30]
這裏是我的有狀態會話bean ...
package com.ray.TEI.ejb;
import com.ray.TEI.model.Program;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import org.jboss.ejb3.annotation.CacheConfig;
@Stateful
@CacheConfig(maxSize = 0, idleTimeoutSeconds = 0)
public class ProgramServiceBean {
@PersistenceContext(unitName="TEI", type=PersistenceContextType.EXTENDED)
protected EntityManager em;
public void test() {
System.out.println("test");
}
public Program findBySlug(String urlSlug) {
System.out.println("findBySlug " + urlSlug);
return em.createNamedQuery("Program.findBySlug", Program.class)
.setParameter("urlSlug", urlSlug)
.getSingleResult();
}
}
這裏是託管bean ...
package com.ray.TEI.controller;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import com.ocpsoft.pretty.faces.annotation.URLAction;
import com.ocpsoft.pretty.faces.annotation.URLMapping;
import com.ocpsoft.pretty.faces.annotation.URLQueryParameter;
import com.ray.TEI.ejb.ProgramServiceBean;
import com.ray.TEI.model.Program;
@Named
@RequestScoped
@URLMapping(
id="uuts",
pattern="/#{programSlug:uutsController.programSlug}/uuts",
viewId="/uuts.xhtml"
)
public class UutsController {
@Inject private ProgramServiceBean programServiceBean;
private String programSlug;
private Program program;
@URLQueryParameter("new")
private Boolean displayAddForm = false;
@URLAction
public String loadData() {
System.out.println("loadData programSlug = " + programSlug);
if (programSlug != null) {
System.out.println("programServiceBean = " + programServiceBean);
programServiceBean.test();
program = programServiceBean.findBySlug(programSlug);
System.out.println("loadData program = " + program.getName());
}
if (program == null) {
return "pretty:error";
}
return null;
}
public String getProgramSlug() {
return programSlug;
}
public void setProgramSlug(String programSlug) {
this.programSlug = programSlug;
}
//other getters/setters
}
任何想法是什麼問題?
感謝, 傑森
(順便說一句,我使用JBoss 6.1決賽)