Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.LinkageError: loader constraint violation: when resolving interface method javax.servlet.jsp.JspApplicationContext.getExpressionFactory()
    primarykey
    data
    text
    <p>I am trying to connect the JSF to database.</p> <p>This are the files</p> <p>web.xml</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt; &lt;display-name&gt;JavaServerFaces&lt;/display-name&gt; &lt;resource-ref&gt; &lt;description&gt;MySQL Datasource example&lt;/description&gt; &lt;res-ref-name&gt;jdbc/mkyongdb&lt;/res-ref-name&gt; &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; &lt;res-auth&gt;Container&lt;/res-auth&gt; &lt;/resource-ref&gt; &lt;!-- Change to "Production" when you are ready to deploy --&gt; &lt;context-param&gt; &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt; &lt;param-value&gt;Development&lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- Welcome page --&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;default.xhtml&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;!-- JSF mapping --&gt; &lt;servlet&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;!-- Map these files with JSF --&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;*.faces&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p></p> <p>context.xml</p> <pre><code> &lt;Context&gt; &lt;Resource name="jdbc/mkyongdb" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="root" password="root" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/mkyongdb"/&gt; &lt;/Context&gt; </code></pre> <p>Default.xhtml</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" &gt; &lt;h:head&gt; &lt;h:outputStylesheet library="css" name="table-style.css" /&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;h1&gt;JSF 2.0 + JDBC Example&lt;/h1&gt; &lt;h:dataTable value="#{customer.getCustomerList()}" var="c" styleClass="order-table" headerClass="order-table-header" rowClasses="order-table-odd-row,order-table-even-row" &gt; &lt;h:column&gt; &lt;f:facet name="header"&gt; Customer ID &lt;/f:facet&gt; #{c.customerID} &lt;/h:column&gt; &lt;h:column&gt; &lt;f:facet name="header"&gt; Name &lt;/f:facet&gt; #{c.name} &lt;/h:column&gt; &lt;h:column&gt; &lt;f:facet name="header"&gt; Address &lt;/f:facet&gt; #{c.address} &lt;/h:column&gt; &lt;h:column&gt; &lt;f:facet name="header"&gt; Created Date &lt;/f:facet&gt; #{c.created_date} &lt;/h:column&gt; &lt;/h:dataTable&gt; &lt;/h:body&gt; &lt;/html&gt; </code></pre> <p>CustomerBean.java</p> <pre><code> package com.mkyong; import java.io.Serializable; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import com.mkyong.customer.model.Customer; @ManagedBean(name="customer") @SessionScoped public class CustomerBean implements Serializable{ //resource injection @Resource(name="jdbc/mkyongdb") private DataSource ds; //if resource inject is not support, you still can get it manually. /*public CustomerBean(){ try { Context ctx = new InitialContext(); ds = (DataSource)ctx.lookup("java:comp/env/jdbc/mkyongdb"); } catch (NamingException e) { e.printStackTrace(); } }*/ //connect to DB and get customer list public List&lt;Customer&gt; getCustomerList() throws SQLException{ if(ds==null) throw new SQLException("Can't get data source"); //get database connection Connection con = ds.getConnection(); if(con==null) throw new SQLException("Can't get database connection"); PreparedStatement ps = con.prepareStatement( "select customer_id, name, address, created_date from customer"); //get customer data from database ResultSet result = ps.executeQuery(); List&lt;Customer&gt; list = new ArrayList&lt;Customer&gt;(); while(result.next()){ Customer cust = new Customer(); cust.setCustomerID(result.getLong("customer_id")); cust.setName(result.getString("name")); cust.setAddress(result.getString("address")); cust.setCreated_date(result.getDate("created_date")); //store all data into a List list.add(cust); } return list; } } </code></pre> <p>Customer.java</p> <pre><code> package com.mkyong.customer.model; import java.util.Date; public class Customer{ public long customerID; public String name; public String address; public Date created_date; public long getCustomerID() { return customerID; } public void setCustomerID(long customerID) { this.customerID = customerID; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public Date getCreated_date() { return created_date; } public void setCreated_date(Date created_date) { this.created_date = created_date; } } </code></pre> <p>pom.xml</p> <pre><code> &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.mkyong.common&lt;/groupId&gt; &lt;artifactId&gt;JavaServerFaces&lt;/artifactId&gt; &lt;packaging&gt;war&lt;/packaging&gt; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt; &lt;name&gt;JavaServerFaces Maven Webapp&lt;/name&gt; &lt;url&gt;http://maven.apache.org&lt;/url&gt; &lt;repositories&gt; &lt;repository&gt; &lt;id&gt;java.net.m2&lt;/id&gt; &lt;name&gt;java.net m2 repo&lt;/name&gt; &lt;url&gt;http://download.java.net/maven/2&lt;/url&gt; &lt;/repository&gt; &lt;/repositories&gt; &lt;dependencies&gt; &lt;!-- MySQL database driver --&gt; &lt;dependency&gt; &lt;groupId&gt;mysql&lt;/groupId&gt; &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt; &lt;version&gt;5.1.9&lt;/version&gt; &lt;/dependency&gt; &lt;!-- Spring framework --&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring&lt;/artifactId&gt; &lt;version&gt;2.5.6&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-web&lt;/artifactId&gt; &lt;version&gt;2.5.6&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.sun.faces&lt;/groupId&gt; &lt;artifactId&gt;jsf-api&lt;/artifactId&gt; &lt;version&gt;2.0.0-b13&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.sun.faces&lt;/groupId&gt; &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt; &lt;version&gt;2.0.0-b13&lt;/version&gt; &lt;/dependency&gt; &lt;!-- EL 2.2 to support method parameter in EL --&gt; &lt;dependency&gt; &lt;groupId&gt;org.glassfish.web&lt;/groupId&gt; &lt;artifactId&gt;el-impl&lt;/artifactId&gt; &lt;version&gt;2.2&lt;/version&gt; &lt;/dependency&gt; &lt;!-- http://repo1.maven.org/maven2/ --&gt; &lt;dependency&gt; &lt;groupId&gt;javax.servlet&lt;/groupId&gt; &lt;artifactId&gt;jstl&lt;/artifactId&gt; &lt;version&gt;1.2&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;finalName&gt;JavaServerFaces&lt;/finalName&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;2.3.1&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.6&lt;/source&gt; &lt;target&gt;1.6&lt;/target&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/project&gt; </code></pre> <p>If I run this in Tomcat7 I am getting the following error</p> <pre><code> SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, com/sun/faces/config/ConfigureListener, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature at com.sun.faces.config.ConfigureListener.registerELResolverAndListenerWithJsp(ConfigureListener.java:636) at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:226) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199) 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:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Jun 15, 2012 2:31:32 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerStart Jun 15, 2012 2:31:32 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Context [/JavaServerFaces] startup failed due to previous errors Jun 15, 2012 2:31:32 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc SEVERE: The web application [/JavaServerFaces] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Jun 15, 2012 2:31:32 PM org.apache.coyote.AbstractProtocolHandler start INFO: Starting ProtocolHandler ["http-bio-8080"] Jun 15, 2012 2:31:32 PM org.apache.coyote.AbstractProtocolHandler start INFO: Starting ProtocolHandler ["ajp-bio-8009"] Jun 15, 2012 2:31:32 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 2341 ms </code></pre> <p>Can Anyone help me out to solve this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload