|
|
|||||||||||||||||||||||||||||||||||||||||||||||||
Carol McDonald's Blog
«Sample Store Catalog Application using Visual Web Pack and the Java Persistence APIs |
Main
| Sample Application using JSF, Seam, and Java Persistence APIs on Glassfish »
Sample Application using JSF, Spring 2.0, and Java Persistence APIsPosted by caroljmcdonald on June 19, 2007 at 12:53 PM | Comments (30)Pagination of Data Sets in a Sample Application using JSF, Spring 2.0, and Java Persistence APIs on GlassfishThis Sample Store Catalog app demonstrates the usage of JavaServer Faces, the new Java Persistence APIs, and Spring 2.0 to implement pagination. I took this example Pagination of Data Sets in a Sample Application using JSF, Catalog Facade Stateless Session, and Java Persistence APIs and modified it slightly to use a Spring Bean instead of a EJB 3.0 Stateless Session Bean. If you compare the two, you will see that the code is almost the same, the main difference is the extra xml configuration for Spring, and for me it wasn't easy to get the .xml configuration right. It took looking at several articles, blogs, examples, and some trial and error to get it working. (see the references at the end). download the SpringJPA sample application code Note: I updated the Spring JSF integration part of this application to use the org.springframework.web.jsf.DelegatingVariableResolver instead of a JSF Managed Bean ServiceLocator in order to get a reference to the CatalogService Spring Bean from the Spring application context. Explanation of the usage of JSF, Spring 2.0 , and Java Persistence APIs in a sample Store Catalog ApplicationThe image below shows the Catalog Listing page, which allows a user to page through a list of items in a store.![]() The List.jsp page uses a JSF dataTable
component to display a list of
catalog itemsThe dataTable component is useful when you want to show a set of results in a table. In a JavaServer Faces application, the UIData
component
(the superclass of dataTable) supports binding to a collection of
data objects. It does the
work of iterating over each record in the data source. The HTML dataTable
renderer
displays the data as an HTML table. In the List.jsp web page the dataTable is defined as shown below: (Note: Red colors are for Java EE tags, annotations code, Blue for Spring specific and Green for my code or variables)
The value attribute of a dataTable
tag references the data to be included
in the table. The var
attribute specifies a
name that is used by the components within the dataTable
tag as an alias to the data referenced in the value
attribute of dataTable. In the dataTable
tag from the List.jsp
page, the value attribute points to a list
of catalog items. The var
attribute points
to a single item in that list. As the UIData
component iterates through the list, each reference to dataTableItem points to the current item in the
list.The dataTable's value
is bound to the items
property
of the item controller
class, ItemController,
which is defined in the
faces-config.xml file:
This ItemController ManagedBean items
property is defined as shown below:
The getItems() method wraps a List of item objects, returned from the catalogService, in a DataModel. UIData,
the superclass of dataTable,
supports data binding to a
collection of data objects represented by a DataModel
instance. The data
collection underlying a DataModel instance is modeled as a collection
of row objects that can be accessed by a row index. The APIs
provide mechanisms to position to a specified row index, and to
retrieve an object that represents the data that corresponds to the
current row index. The Item
properties Name, Photo, and price are
displayed with the column
component:
The column
tags represent columns of data in a UIData
component. While
the UIData component is iterating over the rows of data, it processes
the UIColumn component associated with each column tag for each row in
the table.The UIData component iterates through the list
of items
(item.items)
and displays the dataTableItem.price.
Each
time UIData iterates through the list of items, it renders one cell in
each column.The dataTable and column tags use facet
to represent parts of the
table that are not repeated or updated. These include headers,
footers,
and captions. The recommended way to integrate Spring with JSF is to configure the Spring DelegatingVariableResolver
in the
faces-context.xml. The <application>
<variable-resolver>
elements in a faces-config.xml file allows a Faces-based application to
register a custom replacement class for the implementation of the
standard Faces VariableResolver
implementation. The Spring DelegatingVariableResolver
first delegates to the original resolver of the underlying JSF
implementation, then to the Spring root
WebApplicationContext. This
allows you to configure Spring Beans as managed properties of your JSF
Managed Beans. For example, below the catalogService
Spring
Bean is configured as a managed property of the
ItemController
JSF ManagedBean:
The catalogService,
and its implementation CatalogDAO,
is defined as a Spring
bean in the Spring configuration resource file /WEB-INF/applicationContext.xml :
<property
name="catalogService"> refers to the ItemController setCatalogService
method. The Spring root
WebApplicationContext will inject the catalogService
Spring Bean
into the catalogService
property
of the ItemController
JSF
ManagedBean :
For more information on using JSF with Spring, see Spring - Java/J2EE Application Framework Integrating with JavaServer Faces . Using the Java Persistence API (JPA) with Spring 2.0The Spring beanCatalogDAO
uses the Java
Persistence API
EntityManager
Query object to return a list of items.
The CatalogDAO annotates the field private EntityManager em;
with @PersistenceContext
, which causes an entity manager to be
injected. (note that using the
@PersistenceContext annotation is the same
way an
Entity Manager is injected for a EJB
3.0 Session Bean.)
The Java Persistence Query
APIs are used to create and execute queries that can return a
list of results. The JPA Query interface provides
support for pagination via the setFirstResult() and setMaxResults()
methods:
In the code below, we show the | |||||||||||||||||||||||||||||||||||||||||||||||||
| Code Sample from: Item.java |
@Id @ManyToOne public String getName() { public BigDecimal getPrice() { |
ItemController
ManagedBean pages through the list of Items
by
maintaining the firstItem and batchSize attributes and passing these as
parameters to the CatalogService getItems(firstItem,
batchSize) method.
The ItemController's
<managed-bean-scope> is
defined as session,
a JSF Managedbean
with session scope will be stored in the session meaning that the
bean's properties will stay alive for the life of the Http Session.ItemController
ItemCount
property is used to get and display
the number of Catolog items
in the data base on the List.jsp page:| Code Sample from: List.jsp |
|
ItemController
ItemCount property
is defined as shown below:| Code Sample from: ItemController.java |
|
ItemController
getItemCount()
method calls the CatalogService
interface to get
the count of the list of items. The CatalogDAO
Spring bean getItemCount()
method uses the JPA Query interface to get the count of
all items in the database item table:Code Sample from: CatalogDAO.java |
public class CatalogDAO
implements CatalogService
{ public int getItemCount()
{ |
commandLink
is used to provide a link to click on to
display the next page of items. The commandLink
tag represents an HTML hyperlink and is rendered as an HTML <a> element. The commandLink
tag is used to submit an action event
to the application. | Code Sample from: List.jsp |
|
commandLink action
attribute
references the ItemController
backing bean next()
method which calculates
the
next page's first row number and returns a logical outcome
String, which causes the List.jsp page
to display the next page's
list .
The ItemController
next
method is defined as shown below:Code Sample from: ItemController.java |
public String next() { |
NavigationHandler
matches the logical outcome, item_list
against the navigation rules in the application configuration resource
file faces-config.xml
to determine which page to access next. In this case, the
JavaServer Faces implementation loads the List.jsp
page after this method returns.| Code Sample from: faces-config.xml |
<navigation-rule>item_list</from-outcome> |
commandLink is
used to provide a link to click on to
display the previous page of items. This commandLink
action attribute
references the ItemController
prev() method
that
calculates the
previous page's first row number and returns a logical outcome
String, which causes the List page to display the previous page of
items :| Code Sample from: List.jsp |
|
ItemController
prev()
method is defined as shown
below: Code Sample from: ItemController.java |
public String prev()
{item_list"; |
ommandLink
is used to provide a link to click on to
display a page with the item details. This commandLink
action attribute
references The ItemController
detailSetup()
method:| Code Sample from: List.jsp |
|
ItemController
detailSetup()
method gets the item
data from the
current row of the dataModel,
and returns a string which causes the
Detail.jsp
page to display
the item details :Code Sample from: ItemController.java
|
|
NavigationHandler
matches the logical outcome, item_detail
against the navigation rules in the application configuration resource
file to determine which page to access next. In this case, the
JavaServer Faces implementation loads the Detail.jsp
page after this method returns.| Code Sample from: faces-config.xml |
|
outputText
component to display the ItemController
ManagedBean's item
properties:| Code Sample from: detail.jsp |
|
Download The SpringJPA application. Unzip the code. From Netbeans do Open Project and select the Netbeans project SpringJPA from the unzipped directory. The SpringJPA application is a NetBeans Enterprise Application Project, which is actually comprised of 2 projects: SpringJPA and SpringJPA-war. SpringJPA-war is a Java EE Module of the SpringJPA project. SpringJPA-war generates the war file and SpringJPA generates the ear file which contains the war.
| Code Sample from: applicationContext.xml |
<?xml
version="1.0"
encoding="UTF-8"?> |
| Code Sample from: web.xml |
|
DelegatingVariableResolver and
any Spring beans (i.e. catalogService)
referenced as JSF
Managed Bean (i.e. ItemController) properties
to the faces-config.xml : | Code Sample from: faces-config.xml |
<application>
<managed-property> </managed-bean> |
I also wrote an example like this using Spring 2, a4j, richfaces, hibernate-based jpa (not toplink) with 1 more feature which is data can be sorted by columns. So my questions are not about the techniques:
1. If we use Spring 2, JSF and JPA, why is Glassfish chosen but not something "lighter" like Tomcat or Jetty?
2. This is an article about Spring, JSF, JPA, but I'd like to ask your opinion about something else (so this question must be off-topic). If you use Glassfish, are you going to use Spring, JSF, JPA and then Spring WebFlow (when you need conversation, flow scopes) and then Acegi (when you need authorization and authentication). There's is an intergration between acegi and jsf, but it's, in my opinion, not famous as acegi & jsp (so I don't know how well it performs). Thus, is it better if Seam is chosen to replace Spring, Spring WebFlow and Acegi (and we'll be "closer" to the standard")?
Posted by: dxxvi on June 20, 2007 at 01:41 PM
hi, I wrote this to show a sample app using spring with glassfish, because sometimes I got the question why should I use Java EE/glassfish instead of Spring/Tomcat , so I wanted to show its not either or , you can use them together. Interface21 (the company behind the spring framework) is a glassfish partner.
1) Why is Tomcat or Jetty "lighter" ? the application code is ~ the same for both, actually now Spring requires more xml files than Java EE. Glassfish has hot deploy and the startup time for V3 is supposed to be really fast. I don't really want to debate which is better because I'm not an expert on Tomcat, I think the choice depends on your requirements. Listening to Wotif.com talk at JavaOne they gave some good reasons why they chose Glassfish. Performance tests for Grizzly (the glassfish web container) are very good. With Glassfish you get Comet, HADB, OpenESB , BPEL...
2) I haven't used WebFlow. I've implemented apps with j2ee web authentication ejb authorization ldap, jaas, servlet filter... I've only looked at Acegi, it looks interesting but I haven't looked at it with JSF. I think Seam is really neat, I plan on modifying my app for Seam next. Seam features are going into the Web Beans standard , see the JavaOne session Web Beans Update TS-4089. I don't think I can answer your questions completely, depends on the project, company....
Posted by: caroljmcdonald on June 20, 2007 at 02:55 PM
Well the lighter is mostly regarding the startup times, most people especially in debugging mode (The Eclipse Hotplug often is the cause of this) have to start the app server lots of times every day for development, so getting good startup times is crucial, that is one of the reasons why many people develop under tomcat / jetty and then use another app server for deployment.
Posted by: werpu on June 21, 2007 at 02:10 AM
right , yes right that does make testing your code faster. like I said there is hot deploy, and V3 is supposed to be lot faster startup.
Posted by: caroljmcdonald on June 21, 2007 at 06:57 AM
Hi McDonald,
After i create application follow your tutorial, I get the following error:
2007-07-06 11:53:47,806 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/springpoc].[Faces Servlet]] - Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalArgumentException: Unknown entity bean class: class net.j2mm.springpoc.dao.domain.Item, please verify that this class has been marked with the @Entity annotation.
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:291)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.find(EntityManagerImpl.java:133)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:180)
at $Proxy14.find(Unknown Source)
at net.j2mm.springpoc.service.CatalogDAO.getItem(CatalogDAO.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy17.getItem(Unknown Source)
at net.j2mm.springpoc.web.action.ItemController.getTesting(ItemController.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
IS there anyone have such problem?
Thanks for your help
Posted by: jyzhou817 on July 05, 2007 at 08:58 PM
Hi, I don't know what the problem is. With Netbeans you can generate the Entity Classes and the Persistence Unit from the DB tables. Did you try that? You can post glassfish questions here http://forums.java.net/jive/forum.jspa?forumID=56
Posted by: caroljmcdonald on July 06, 2007 at 06:57 AM
I wrote FacesGoodies, to give a starting point, when using JSF+Spring+JPA
FacesGoodies uses (check out the trunk):
JSF 1.2 (Apache MyFaces 1.2.0-SNAPSHOT), Trinidad 1.2.1, Facelets, Shale, Spring 2.0, JPA (Java Persistence API) and Toplink Essentials
FacesGoodies
Posted by: mwessendorf on July 09, 2007 at 02:18 AM
Hi, br/
Thanks for your reply.
Actually, I can unit test the DAO by extends AbstractJpaTests. the result is correct. br/
But, when I try to deploy it in tomcat, I get the error as what i posted.
br/
my environment is: tomcat 5.5.23, mysql 5.0
I am struggling for this problem for quite few days. Is it because of JSF?
Thanks
Posted by: jyzhou817 on July 09, 2007 at 03:02 AM
Hi Jyzhou817
I guess your issue is using
Try:
There is also a special module for Tomcat.
Perhaps checking out FacesGoodies, does help as well
Posted by: mwessendorf on July 09, 2007 at 03:15 AM
ok...
try:
org.springframework.instrument.classloading.SimpleLoadTimeWeaver
instead of
org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver
for the loadTimeWeaver
Posted by: mwessendorf on July 09, 2007 at 03:15 AM
Hi, br/
Thanks for your reply.
Actually, I can unit test the DAO by extends AbstractJpaTests. the result is correct. br/
But, when I try to deploy it in tomcat, I get the error as what i posted.
br/
my environment is: tomcat 5.5.23, mysql 5.0
I am struggling for this problem for quite few days. Is it because of JSF?
Thanks
Posted by: jyzhou817 on July 09, 2007 at 03:34 AM
Hi,
Thanks very much.
I am using org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver
and I tries org.springframework.instrument.classloading.SimpleLoadTimeWeaver
also. Still the same result.
Thanks
Posted by: jyzhou817 on July 09, 2007 at 03:36 AM
Hi,
Could you please attach the jars you used when deploy to glassfish server?
when i deploy it to glassfish, i get the following error:
[#|2007-07-13T10:15:22.004+0800|WARNING|sun-appserver-pe9.0|javax.enterprise.resource.webcontainer.jsf.lifecycle|_ThreadID=19;_ThreadName=httpWorkerThread-8080-1;_RequestID=499f4b4c-4d0c-4191-bf99-c19e7ba6b1db;|executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@11c5809) threw exception
javax.faces.FacesException: org.apache.jasper.JasperException: jsp.error.beans.property.conversion
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:418)
at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:480)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:125)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:133)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
Caused by: org.apache.jasper.JasperException: jsp.error.beans.property.conversion
at org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromPropertyEditorManager(JspRuntimeLibrary.java:900)
at org.apache.jsp.item.List2_jsp._jspx_meth_h_messages_0(List2_jsp.java:150)
at org.apache.jsp.item.List2_jsp._jspx_meth_f_view_0(List2_jsp.java:117)
at org.apache.jsp.item.List2_jsp._jspService(List2_jsp.java:81)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:412)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:318)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:850)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:697)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:532)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:465)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:353)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:413)
... 30 more
Thanks alot.
Posted by: jyzhou817 on July 12, 2007 at 07:58 PM
HI, I uploaded the .ear file to
https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=7555
Posted by: caroljmcdonald on July 12, 2007 at 08:22 PM
I follow your example
and was able to get Spring beans injection into the
JSF container. I am trying to use Seam annotation instead of managed-bean
definition in the faces-context.xml. So instead of
<managed-bean>
<managed-bean-name>item</managed-bean-name>
<managed-bean-class>
sessionpagination.ItemController
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>catalogService</property-name>
<value>#{catalogService}</value>
</managed-property>
</managed-bean>
I tried to do something like this in the class:
@Scope(ScopeType.SESSION)
@Name(“item”)
public class ItemController implements Serializable
{
@In(“#{catalogService }”)
private CatalogService catalogService ;
private String test;
public void setCatalogService(CatalogService
catalogService) {
this.catalogService
= catalogService;
}
public String getTest() {
return “testing”;
}
}
But I was not able to
use this bean on the jsf pages. Looks like its not instantiated in the JSF container. Is there any
other settings or configuration I have to do to get it injected by Seam? Thank
you.
Posted by: paulkim on July 27, 2007 at 07:22 AM
I haven't tried seam & spring together. If you are going to use Seam on Glassfish you will need the Seam jars and configuration in your project (see my or brian leonard's blog on seam on glassfish).
Posted by: caroljmcdonald on July 27, 2007 at 07:31 AM
Regarding the "the lighter is mostly regarding the startup times", check out this information from Raible's blog:
http://raibledesigns.com/rd/category/Java
Startup Time with no applications deployed:
Tomcat 6: 3 seconds
GlassFish 2: 8 seconds
Startup Time with AppFuse 2.0 (Struts + Hibernate version) as a WAR
Tomcat 6: 15 seconds
GlassFish 2: 16 seconds
comparison of how long it takes for both servers to pick up a new WAR (and start the application) when it's dropped into their autodeploy directories.
Tomcat 6: 14-16 seconds
GlassFish 2: 9 seconds
Posted by: caroljmcdonald on September 24, 2007 at 07:11 AM
Hi Carol i am having problem saving data using JSF Spring JPA
I tried writing all code here but it is comin all on one line
I have raised the same question in Spring forum without help
The link is as below
http://forum.springframework.org/showthread.php?t=47355
Can you please help
Posted by: purnendu9 on December 12, 2007 at 11:43 PM
I haven't had a chance to try out Spring 2.5 with Glassfish yet. This question would be better answered by a spring forum
Posted by: caroljmcdonald on December 13, 2007 at 07:18 PM
I am having problems getting this to run. I get a java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException
I have set this up using Netbeans 6.0 and Spring 2.5.
I also created the database in Netbeans 6.0 and can view jdbc:derby://localhost:1527/pet-catalog tables and there associated data.
For reference here is the full expeption shown on the Glassfish debug tab
naming.bind
Null component com.sun.appserv:type=JspMonitor,name=jsp,WebModule=//server/SpringJPA,J2EEApplication=null,J2EEServer=server
WEB0207: Error starting web context StandardEngine[com.sun.appserv].StandardHost[server].StandardContext[/SpringJPA] on virtual server server
java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException
at com.sun.enterprise.web.WebModuleListener.loadPersistenceUnits(WebModuleListener.java:193)
at com.sun.enterprise.web.WebModuleListener.lifecycleEvent(WebModuleListener.java:168)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:143)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5086)
at com.sun.enterprise.web.WebModule.start(WebModule.java:327)
at com.sun.enterprise.web.LifecycleStarter.doRun(LifecycleStarter.java:58)
at com.sun.appserv.management.util.misc.RunnableBase.runSync(RunnableBase.java:296)
at com.sun.appserv.management.util.misc.RunnableBase.run(RunnableBase.java:330)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException
at com.sun.enterprise.server.PersistenceUnitInfoImpl._getJtaDataSource(PersistenceUnitInfoImpl.java:283)
at com.sun.enterprise.server.PersistenceUnitInfoImpl.(PersistenceUnitInfoImpl.java:116)
at com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java:121)
at com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java:84)
at com.sun.enterprise.web.WebModuleListener.loadPersistenceUnits(WebModuleListener.java:190)
... 13 more
Caused by: javax.naming.NameNotFoundException
at com.sun.enterprise.naming.TransientContext.resolveContext(TransientContext.java:268)
at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:191)
at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
at com.sun.enterprise.naming.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:111)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:339)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.sun.enterprise.connectors.ConnectorResourceAdminServiceImpl.lookup(ConnectorResourceAdminServiceImpl.java:196)
at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:1098)
at com.sun.enterprise.server.PersistenceUnitInfoImpl.lookupPMDataSource(PersistenceUnitInfoImpl.java:294)
at com.sun.enterprise.server.PersistenceUnitInfoImpl._getJtaDataSource(PersistenceUnitInfoImpl.java:281)
... 17 more
Posted by: andreakendall on January 09, 2008 at 03:36 PM
A few more things.
The setup.xml file does not build as shipped it references an unknown tools dependancy.
I do not see any SpringJPA-war module. Should I download the Spring ear and get the .war from that?
Posted by: andreakendall on January 09, 2008 at 03:45 PM
I replaced this ear version with a version that just has a .war for my blog on spring 2.5, jsf, and jpa. Please try again following the instructions on the newer blog entry. From your error looks like there is a problem with the persistence unit.
Posted by: caroljmcdonald on January 09, 2008 at 04:04 PM
Great article - just what I was looking for - thx Carol
Posted by: amoore_qualcomm_com on March 19, 2008 at 09:48 AM
Hi Carol
When trying to setup the sample application I ran into the problem that has been mentioned earlier i.e. the setup.xml does not build as it cannot find the tools dependency.
To fix this problem I have made changes to some files that are part of the setup directory. Download this jar and unjar it into the setup directory. Ensure that you have edited the setup/build.properties to have the value of javaee.home to point to the root of your GlassFish application server installation. Then you can run the command "ant -f setup.xml setup" or "ant -f setup.xml unsetup" from the setup directory successfully.
Thanks
Pramod Gopinath
Posted by: pramodgo on April 16, 2008 at 04:49 PM
Hi Carol
When I made the post somehow the href did not translate properly. The jar file can be found at : http://blogs.sun.com/pramodg/resource/spring/carol_SpringJPA.jar.
Thanks
Pramod
Posted by: pramodgo on April 16, 2008 at 04:50 PM
Pramod, I added your setup fixes to the sample download zip
Posted by: caroljmcdonald on April 19, 2008 at 11:30 AM
Nice article :-)
One consideration -- I don't think the ItemController bean needs to be in your application.xml file. The ContextLoaderListener will create the catalogService bean and the DelegatingVariableResolver will automagically inject the ref to catalogService into your ItemController. (YMMV)
Posted by: netminkey on June 04, 2008 at 06:51 AM
you are right, actually I already took the ItemController bean out of the application.xml file in the code, I need to update the blog text.
Posted by: caroljmcdonald on June 04, 2008 at 07:02 AM
|
|