- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
经过一些实验,这在使用 CDI bean 时似乎是一个问题,与我最初假设的 PrimeFaces 无关。
如果我使用@ManagedBean 将 TableBeanLazy 更改为托管 Bean,那么构造函数和 @PostConstruct 方法只会被调用一次,正如我所期望的。
任何人都可以对此有所了解吗?
================================================== =
我对 JSF 和 PrimeFaces 还很陌生,因此将不胜感激任何指导。我搜索了其他帖子,并阅读了许多类似的帖子,但找不到解决方案。
我正在尝试让 PrimeFaces Showcase 站点上的延迟加载数据表示例在我的项目中工作,但由于 bean 类的行为不符合我的预期,我遇到了问题。
我对来自 PrimeFaces 站点的示例代码进行了一些更改:- 将 TableBean 类重命名为 TableBeanLazy;为类添加了注释;分配的静态字符串数组;将初始化从构造函数移至 @PostConstruct initialise() 方法;分配了汽车成员变量。
我还向构造函数和 @PostConstruct 方法添加了跟踪消息,这表明在首次显示表时多次调用这两者,每次单击搜索图标时多次调用,以及在每个字符条目中多次调用过滤字段。
这会导致每次执行操作时都会重新创建 Car 对象的随机列表,因此排序和过滤器永远不会产生预期的结果 - 它们在 PrimeFaces Showcase 站点上直接运行示例时会这样做。
虽然我最初使用的是@ViewScoped,但我也尝试过@RequestScoped 和最后的@SessionScoped,但都以相同的方式运行。
对构造函数和 @PostConstruct 的多次调用是否是 bean 的预期行为?
如果是这样,PrimeFaces Showcase 站点上给出的示例代码如何工作?
我该如何解决?
环境
PrimeFaces 3.5
JSF 2.1
JDK 1.7
GlassFish Server Open Source Edition 3.1.2.2 (build 5)
Mojarra 2.1.6 (SNAPSHOT 20111206)
Netbeans IDE 7.3
Windows 7 Pro x64
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="./resources/templates/platform_tpl.xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:define name="body">
<h2 style="margin-top: 0px; padding-top: 0px;">Cars List</h2>
<h:form id="form">
<p:dataTable var="car" value="#{tableBeanLazy.lazyModel}" paginator="true" rows="10"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{tableBeanLazy.selectedCar}" id="carTable" lazy="true">
<p:column headerText="Model" sortBy="#{car.model}" filterBy="#{car.model}">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="Year" sortBy="#{car.year}" filterBy="#{car.year}">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Manufacturer" sortBy="#{car.manufacturer}" filterBy="#{car.manufacturer}">
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column headerText="Color" sortBy="#{car.color}" filterBy="#{car.color}">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package BackEnd;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.SessionScoped;
import javax.inject.Named;
import org.primefaces.model.LazyDataModel;
@Named(value = "tableBeanLazy")
@SessionScoped
public class TableBeanLazy
{
static String[] colors = new String[10];
static String[] manufacturers = new String[10];
static String[] models = new String[5];
private LazyDataModel<Car> lazyModel;
private Car selectedCar;
private List<Car> cars;
static
{
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
manufacturers[0] = "Mercedes";
manufacturers[1] = "BMW";
manufacturers[2] = "Volvo";
manufacturers[3] = "Audi";
manufacturers[4] = "Renault";
manufacturers[5] = "Opel";
manufacturers[6] = "Volkswagen";
manufacturers[7] = "Chrysler";
manufacturers[8] = "Ferrari";
manufacturers[9] = "Ford";
models[0] = "Sports";
models[1] = "Saloon";
models[2] = "SUV";
models[3] = "Hybrid";
models[4] = "Estate";
}
public TableBeanLazy()
{
System.out.println("--> In constructor for TableBeanLazy");
}
@PostConstruct
public void initialise()
{
System.out.println("--> In initialise for TableBeanLazy");
cars = new ArrayList<Car>();
populateRandomCars(cars, 5);
lazyModel = new LazyCarDataModel(cars);
}
public Car getSelectedCar()
{
return selectedCar;
}
public void setSelectedCar(Car selectedCar)
{
this.selectedCar = selectedCar;
}
public LazyDataModel<Car> getLazyModel()
{
return lazyModel;
}
private void populateRandomCars(List<Car> list, int size)
{
System.out.println("--> In populateRandomCars for TableBeanLazy");
for(int i = 0 ; i < size ; i++)
{
list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
}
}
private String getRandomColor()
{
return colors[(int)(Math.random() * 10)];
}
private String getRandomManufacturer()
{
return manufacturers[(int) (Math.random() * 10)];
}
private String getRandomModel()
{
return models[(int)(Math.random() * 5)];
}
private int getRandomYear()
{
return (int)(Math.random() * 50 + 1960);
}
}
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
at org.primefaces.model.LazyDataModel.setRowIndex(LazyDataModel.java:62)
at org.primefaces.component.api.UIData.setRowModel(UIData.java:409)
at org.primefaces.component.api.UIData.setRowIndex(UIData.java:401)
at org.primefaces.component.api.UIData.processChildren(UIData.java:289)
at org.primefaces.component.api.UIData.processPhase(UIData.java:261)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:227)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:506)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:639)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIForm.visitTree(UIForm.java:344)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
at org.primefaces.model.LazyDataModel.setRowIndex(LazyDataModel.java:62)
at org.primefaces.component.api.UIData.setRowModel(UIData.java:409)
at org.primefaces.component.api.UIData.setRowIndex(UIData.java:401)
at org.primefaces.component.api.UIData.processChildren(UIData.java:289)
at org.primefaces.component.api.UIData.processPhase(UIData.java:261)
at org.primefaces.component.api.UIData.processValidators(UIData.java:241)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:508)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:639)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIForm.visitTree(UIForm.java:344)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1170)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
at org.primefaces.model.LazyDataModel.setRowIndex(LazyDataModel.java:62)
at org.primefaces.component.api.UIData.setRowModel(UIData.java:409)
at org.primefaces.component.api.UIData.setRowIndex(UIData.java:401)
at org.primefaces.component.api.UIData.processChildren(UIData.java:289)
at org.primefaces.component.api.UIData.processPhase(UIData.java:261)
at org.primefaces.component.api.UIData.processUpdates(UIData.java:253)
at org.primefaces.component.datatable.DataTable.processUpdates(DataTable.java:550)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:510)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:639)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIForm.visitTree(UIForm.java:344)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1229)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
INFO: --> In constructor for TableBeanLazy
INFO: --> In initialise for TableBeanLazy
INFO: --> In populateRandomCars for TableBeanLazy
最佳答案
这是您对 CDI 和 JSF 的第一条建议 - 切勿将 CDI 与 JSF 注释混用。
你的问题是你使用 @javax.inject.Named
带有 javax.faces.bean.SessionScoped
的 CDI 注释- JSF 注释。
在 CDI 中,您将执行以下操作:
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named(value = "tableBeanLazy")
@SessionScoped
public class TableBeanLazy {...}
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ManagedBean;
@ManagedBean(value = "tableBeanLazy")
@SessionScoped
public class TableBeanLazy {...}
@javax.faces.bean.ViewScoped
盒子外面。要在 CDI 中获取它,请查看 Apache Deltaspike。
关于jsf - CDI bean 构造函数和@PostConstruct 多次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16796320/
我对下面代码的结果有点困惑。 父 Controller : @Controller public abstract class ParentController{ @PostConstruct pub
我有这样的设置: Bean类: private final Map configCache = new HashMap<>(); @PostConstruct private void fillCac
这似乎不正确。我正在清理代码,只是注意到了这一点。每个ajax请求都会触发我的@PostConstruct bean的构造函数和@ViewScoped。即使是简单的数据库分页也会触发它。 我under
根据answer of BalusC ,我用过 FacesContext.getCurrentInstance().getExternalContext().redirect(url); 在我的 @P
我正在使用 Spring 开发一个 Java 小型应用程序,所以我有这个服务: public class AccountService implements UserDetailsService {
问题:entityManager.unwrap(SessionImplementor.class) 导致没有可用的事务实体管理器异常。 代码: @Component public class Hibe
我想使用 @PostConstruct 在我的 web 应用程序中初始化一个 bean,但我无法让它工作。 我已经在新项目中重新创建了该问题,但仍然无法正常工作。 我在这里遗漏了一些明显的东西吗?据我
我在 Java SE 应用程序中使用 CDI (Weld)。我制作了一个 Bean,我们称之为 BeanA。 public class BeanA { @PostConstruct p
在托管 bean 中,@PostConstruct 在常规 Java 对象构造函数之后调用。 为什么我要使用 @PostConstruct 来初始化 bean,而不是常规构造函数本身? 最佳答案 因为
我有 spring bean 类 RedisRepo在里面我正在使用@PostConstruct初始化我的数据库连接: @PostConstruct public void init() {
我使用了当前版本的 Eclipse 和 Java。我尝试将 RCP 应用程序从 Java 8 迁移到 Java 11。我的应用程序可以运行,但现在遇到功能问题,因为我必须从代码中删除 @PostC
由于我是 Java EE 7 的新手,所以我创建了一个项目以供学习之用。我创建了一个具有 Request 范围的 CDI bean,如下所示(它只是实现了 Serializable,因为我已经尝试将它
我有一个计划任务,每晚汇总数据。每当我启动应用程序时该任务就会运行,并且我想在应用程序上运行 jUnit 测试时停止它运行。 @Scheduled(cron = "0 0 0 1 * ?") publ
这个问题已经有答案了: How to get access to javax.annotation.Resource at run time in Java 9 (2 个回答) Java 9 migr
我正在 JBoss 上试验 EJB3,开发无状态 bean。基本上一旦部署了模块,我就需要执行一些与加载应用程序设置相关的操作。为此,我将一个方法注释为@PostConstruct,据我所知,API
假设我们有以下类 public abstract class AbstractFoo { @PostConstruct private void doIt() { //
我的 JEE 应用程序中有 2 个单例,我想在启动时对其进行初始化。像这样: @Singleton @Startup public class ServiceB { @EJB priv
我正在编写 JAX-RS 库(不是应用程序)。 我有: abstract class A { @PostConstruct private void constructed_a() {
假设我在 Spring @Configuration 中有这个依赖: @Bean public SomeClass someClass(SomeClass1 someClass1, SomeClass
我将 JSF 2.0 与 GlassFish 3.0 结合使用。 我有以下托管 Bean: @ManagedBean @RequestScoped public class OverviewContr
我是一名优秀的程序员,十分优秀!