Hallo zusammen,
bin JSF/Spring Anfänger und teste gerade ein Beispiel aus einem Buch. Wenn ich die Web-Applikation starte werden, bevor die Startseite angezeigt wird, folgende Exceptions geworfen:
Habe mal ein bischen nach den letzten beiden Fehlermeldungen gegooglet und in verschiedenen Foren gelesen dass es mit der Reihenfolge der im ApplicationContext definierten Spring Beans zusammenhängt, wenn die Beans in Abhängigkeit zueinander stehen. Die Änderung der Bean-Position in der Konfiguration hat aber leider auch nichts gebracht. Sitze schon Stunden an diesem Problem und komme einfach nicht weiter.
Hier noch die .xml, .jsp und .java Dateien der Anwendung:
applicationContextJSF.xml
choosePizza.jsp (Startseite)
PizzaList.java
PizzaConverter.java
Pizza.java (Persistenz-Bean)
bin JSF/Spring Anfänger und teste gerade ein Beispiel aus einem Buch. Wenn ich die Web-Applikation starte werden, bevor die Startseite angezeigt wird, folgende Exceptions geworfen:
Code:
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.faces.el.EvaluationException: Cannot get value for expression '#{pizza}' org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pizza' defined in class path resource [applicationContextJSF.xml]: Cannot resolve reference to bean 'order' while setting bean property 'order'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'order' defined in class path resource [applicationContextJSF.xml]: Cannot resolve reference to bean 'pizza' while setting bean property 'pizzas'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'pizza': Requested bean is currently in creation: Is there an unresolvable circular reference?
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'order' defined in class path resource [applicationContextJSF.xml]: Cannot resolve reference to bean 'pizza' while setting bean property 'pizzas'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'pizza': Requested bean is currently in creation: Is there an unresolvable circular reference?
Hier noch die .xml, .jsp und .java Dateien der Anwendung:
applicationContextJSF.xml
HTML Code:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" default-autowire="byType"> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>errors</value> <value>de.hanser.buch.opiz.auth.messages</value> </list> </property> </bean> <bean id="orderAction" class="de.hanser.buch.opiz.web.jsf.OrderAction"> <property name="orderService" ref="orderService" /> <property name="orderDao" ref="orderDAO" /> <property name="customerAuthService" ref="customerAuthService" /> </bean> <bean id="customerAction" class="de.hanser.buch.opiz.web.jsf.CustomerAction"> <property name="customerService" ref="customerService" /> <property name="customerAuthService" ref="customerAuthService" /> <property name="customerDao" ref="customerDAO" /> <property name="messageSource" ref="messageSource" /> </bean> <bean name="customerAuthService" class="de.hanser.buch.opiz.auth.CustomerAuthServiceImpl"> <property name="authenticationManager" ref="authenticationManager" /> <property name="customerDao" ref="customerDAO" /> </bean> <bean name="pizza" class="de.tutorial.opiz.domain.Pizza" scope="request"> </bean> <bean name="order" class="de.tutorial.opiz.domain.Order" scope="session"> </bean> <bean name="pizzasList" class="de.hanser.buch.opiz.web.jsf.PizzaList"> <property name="toppingDao" ref="toppingDao" /> </bean> <bean name="toppingsList" class="de.hanser.buch.opiz.web.jsf.ToppingList" scope="session"> <property name="toppingDao" ref="toppingDao" /> </bean> <bean name="address" class="de.tutorial.opiz.domain.Address" scope="request"> </bean> <bean name="customer" class="de.tutorial.opiz.domain.Customer" scope="request"> </bean> <bean name="toppingsSelection" class="de.hanser.buch.opiz.web.jsf.ToppingList" scope="request"> </bean> </beans>
HTML Code:
<%@ page contentType="text/html" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <%@ include file="../base/includeHeader.jsp" %> <body> <f:view> <%@ include file="top.jsp"%> <h:form id="form1"> <h3>Wähle eine Standard-Pizza ... </h3> <table> <tr> <td> <h:panelGrid columns="2"> <h:selectOneRadio id="Pizza" value="#{pizza}" layout="pageDirection" required="true"> <f:selectItems value="#{pizzasList.selectionList}" /> <f:converter converterId="pizzaConverter"/> </h:selectOneRadio> <h:message for="Pizza" style="color:red"/> </h:panelGrid> </td> </tr> <tr> <td colspan="2" class="buttonBar"> <h:commandButton type="submit" value="Abbruch" action="cancel" immediate="true" /> <h:commandButton type="submit" value="In den Warenkorb" action="#{orderAction.add}" immediate="false" /> </td> </tr> </table> </h:form> </f:view> </body> </html>
Code:
public class PizzaList extends AbstractSelectionList<Pizza> { private ToppingDAO toppingDao; protected void fillSelectionList() { Topping tomato = toppingDao.getToppingByName("Tomaten").get(0); Topping cheese = toppingDao.getToppingByName("Käse").get(0); Topping ananas = toppingDao.getToppingByName("Ananas").get(0); Pizza margarita = new Pizza("Margarita", new ArrayList<Topping>()); margarita.addTopping(tomato); margarita.addTopping(cheese); addSelectionItem(margarita); Pizza hawaii = new Pizza("Hawaii", new ArrayList<Topping>()); hawaii.addTopping(tomato); hawaii.addTopping(cheese); hawaii.addTopping(ananas); addSelectionItem(hawaii); } private void addSelectionItem(Pizza pizza) { addSelectionItem(pizza.getName(), pizza); } public void setToppingDao(ToppingDAO toppingDao) { this.toppingDao = toppingDao; } }
Code:
public class PizzaConverter implements Converter { public Object getAsObject(FacesContext ctx, UIComponent component, String value) { Pizza selectedPizza = null; if ((value == null) || value.length() == 0) { throw new ConverterException("error.pizzaNull"); } Application app = ctx.getApplication(); ValueBinding bind = app.createValueBinding("#{pizzasList}"); PizzaList typeList = (PizzaList) bind.getValue(ctx); selectedPizza = typeList.getObjectByKey(value); if (selectedPizza == null) { throw new ConverterException("error.pizzaConversion"); } return selectedPizza; } public String getAsString(FacesContext ctx, UIComponent component, Object value) { if (value == null) { return null; } return ((Pizza) value).getName(); } }
Code:
@SuppressWarnings("serial") @Entity @Table(name = "pizza") @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public class Pizza implements Cloneable, Serializable { private static final double BASE_PRICE = 3.0; private Integer id; private String name; private Integer menge; private Order order; private List<Topping> toppings; public Pizza() { this.toppings = new ArrayList<Topping>(); } public Pizza(Integer aPizzaId) { this(); this.id = aPizzaId; } public Pizza(String aName, List<Topping> theToppings) { this.name = aName; this.toppings = theToppings; } @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "PIZZA_ID") public Integer getId() { return id; } public void setId(Integer anId) { this.id = anId; } public String getName() { return name; } public void setName(String name) { this.name = name; } @ManyToOne @JoinColumn(name = "ORDERS_FK") public Order getOrder() { return order; } public void setOrder(Order order) { this.order = order; } public Integer getMenge() { if (this.menge == null) this.menge = 1; return menge; } public void setMenge(Integer menge) { this.menge = menge; } @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "pizza_topping", joinColumns = @JoinColumn(name = "PIZZA_FK"), inverseJoinColumns = @JoinColumn(name = "TOPPING_FK")) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public List<Topping> getToppings() { return toppings; } public void setToppings(List<Topping> toppings) { this.toppings = toppings; } public void addTopping(Topping topping) { this.toppings.add(topping); } @Override public Object clone() { return new Pizza(name, toppings); } @Transient public double getPrice() { double price = BASE_PRICE; for (Topping topping : toppings) { price += topping.getPrice(); } return price; } }
Comment