This question already has answers here:
How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null / throws an error / not usable
(11 answers)
Closed 5 years ago.
I am trying to call my Controller code from xhtml page. My code is like this to upload a excel file. But, this code is not hitting the Controller. Can anyone help me with fixing this?
<h:form name="addBulkTnForm" id="addBulkTnFormId" enctype="multipart/form-data">
<h:panelGroup id="fileUploadPnGrp">
<p:fileUpload mode="simple" value="#{controller.addTnBulkFile}">
</p:fileUpload>
<p:commandButton value="Upload" listener="#{controller.addBulkTnUpload}" ajax="false"></p:commandButton>
</h:panelGroup>
</h:form>
Here are my dependencies
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.14</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.14</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
Have you configured primefaces upload filter from web.xml?
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto|native|commons</param-value> <!-- One of these -->
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
You can check https://www.primefaces.org/docs/guide/primefaces_user_guide_5_2.pdf
Related
I need to use two separate log4j loggers in my Spring project running on tomcat 9. I started by getting the dependencies and placing in my pom.xml:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.17.1</version>
</dependency>
Then I created the xml log configuration file, and afterwards in my web.xml I placed the following:
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
<filter>
<filter-name>log4jServletFilter</filter-name>
<filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>log4jServletFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<context-param>
<param-name>log4jContextName</param-name>
<param-value>PersonLogger</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>file:../conf/properties/PersonLogConfig.xml</param-value>
</context-param>
Then, in my application I used it like so:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
static final Logger LOG = LogManager.getLogger("PersonLogger." + PersonAgentImpl.class);
LOG.info("working");
This all worked without issue, the folder and log file were created and logged to as expected. However when I tried to add a second logger- it would not work. Neither folder/log file would be created. (they both work separately if I comment out one though)
This is how I attempted to set up two instances in my web.xml:
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
<filter>
<filter-name>log4jServletFilter</filter-name>
<filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>log4jServletFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<!-- PersonLogger -->
<context-param>
<param-name>log4jContextName1</param-name>
<param-value>PersonLogger</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration1</param-name>
<param-value>file:../conf/properties/PersonLogConfig.xml</param-value>
</context-param>
<!-- AnimalLogger -->
<context-param>
<param-name>log4jContextName2</param-name>
<param-value>AnimalLogger</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration2</param-name>
<param-value>file:../conf/properties/AnimalLogConfig.xml</param-value>
</context-param>
Any ideas on what might be wrong? From what I understand as long as the param names are different than 2 instances of log4j should be able to work at the same time- using the context name to specify which one is used.
I am working on building spring webservices for an application. I am using apache cxf for creating webservices and maven for building the war. I am using weblogic 12c to deploy the webservice in my PC. I am using "org.codehaus.jackson.jaxrs.JacksonJsonProvider" as the jsonProvider. The code gets deployed in the server running machine without any errors. But when i try to deploy the same code in the client machine that has weblogic 12.2.1 the deployment fails with the following error:
"Jersey" failed to preload on startup in Web application:
"broker-ws.war".
<[ACTIVE] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1490020025257> <BEA-101216> <Servlet: "Jersey" failed to preload on startup in Web application: "broker-ws.war".
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
at javax.servlet.GenericServlet.init(GenericServlet.java:240)
at weblogic.jaxrs.server.portable.servlet.ServletContainer.init(ServletContainer.java:121)
at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:337)
at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:288)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.StubSecurityHelper.initServletInstance(StubSecurityHelper.java:98)
at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:86)
at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:71)
at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:57)
at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:31)
at weblogic.servlet.internal.ServletStubImpl.initStubLifecycleHelper(ServletStubImpl.java:656)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:600)
at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1974)
at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1951)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1841)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2871)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:823)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
I am not explicitly referencing Jersey anywhere in my project, but i am using jax-rs which is looking for Jersey.The weblogic server in my machine had Jersey jars, but the weblogic present in the client machine did not have Jersey jars. I tried adding the following jars to my pom.xml:
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles/jaxrs-ri -->
<dependency>
<groupId>org.glassfish.jersey.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-api</artifactId>
<version>2.5.0-b32</version>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-locator</artifactId>
<version>2.5.0-b32</version>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-utils</artifactId>
<version>2.5.0-b32</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.hk2/hk2-inhabitant-generator -->
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-inhabitant-generator</artifactId>
<version>2.5.0-b19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.inject/javax.inject -->
<!-- https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax-inject -->
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.javax-inject</artifactId>
<version>1_2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles.repackaged/jersey-guava -->
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.25</version>
</dependency>
Yet i am unable to deploy the application without any error. I get a different error now.
java.lang.IllegalStateException: No generator was provided and there
is no default generator registered
Please find below my jax-rs configuration in the spring-config file.
<jaxrs:server id="restService" address="/rest">
<jaxrs:serviceBeans>
<ref bean="userService" />
<ref bean="billingService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean='jsonProvider' />
</jaxrs:providers>
<jaxrs:inInterceptors>
<bean class="com.brokerws.interceptor.WSLoggingRequestInterceptor" />
</jaxrs:inInterceptors>
<jaxrs:outInterceptors>
<bean class="com.brokerws.interceptor.WSLoggingResponseInterceptor" />
</jaxrs:outInterceptors>
</jaxrs:server>
Please find below my web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true" version="3.0">
<display-name>SuppApp</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/app-beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>health-check</servlet-name>
<servlet-class>com.suddenlink.util.HealthCheckServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>health-check</servlet-name>
<url-pattern>/healthCheck</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Logback-MDC-Filter</filter-name>
<filter-class>com.suddenlink.traceability.filter.HttpHeaderServletFilter</filter-class>
<init-param>
<param-name>application_name</param-name>
<param-value>broker-ws</param-value>
</init-param>
<init-param>
<param-name>application_type</param-name>
<param-value>ws</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Logback-MDC-Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Can someone tell me what i am missing here.I tried various solutions given over the internet, but nothing worked for me.
Finally found the root cause for the issue. It was the spring webapp version, which was making the weblogic server look for jersey dependency. I changed the webapp version from 3.0 to 2.5 and the error is gone. Hope this helps somebody who will run into this issue as this took nearly two days to figure what was actually happening.
I am aware that there are similar questions related to this topic. However, none of the answers did help me and I simply can't get my Intellij/Tomcat running correctly.
Tomcat is not able to find any *.xhtml or plain html file. Every single time I try to run the project out of IntellIj I just get the error mentioned in the title. I also tried deploying the project with maven. Didn't work out well (same problem).
I installed Tomcat with Xampp in the default location C:\xampp on a Win10 64 bit machine. Here is how my project is structured:
I defined all my dependencies in the pom.xml plus the plugin to deploy the web app on tomcat:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<!-- Mojarra JSF -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${mojarra.version}</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${mojarra.version}</version>
</dependency>
<!-- PrimeFaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>${primefaces.version}</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.8</version>
</dependency>
What i configured for Tomcat in Intellij: Run/Debug settings in Intellij
I no longer have any idea whatsoever what this could be. Checked URLs multiple times, threw away that declaration for the virtual /faces/* folder in the web.xml. Here's my full web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<listener id="ServiceLocator">
<display-name>InitializeContextListener</display-name>
<listener-class>wuhu.webclient.InitializeContextListener</listener-class>
</listener>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>WUHU_SERVICE_URL</param-name>
<param-value>http://localhost:%s/wuhuservice</param-value>
</context-param>
<context-param>
<param-name>WUHU_SERVICE_PORT</param-name>
<param-value>8123</param-value>
</context-param>
</web-app>
Faulty Maven project structure, answered by JimHawkins in the comments
I am new in spring security I have been done everything in tutorial, but i got this exception.
I have a simple Spring Security + JSF web app:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/security-config.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--JSF -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
security-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<security:http>
<security:intercept-url pattern="/admin" access="ROLE_USER"/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="sajjad" password="414141" authorities="ROLE_USER"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans>
The spring-config.xml is empty.
Here is my dependencies:
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
But i get this exception when i run the application:
25-May-2015 02:35:11.113 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Error listenerStart
25-May-2015 02:35:11.114 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
25-May-2015 02:35:11.125 WARNING [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.doClose Exception thrown from ApplicationListener handling ContextClosedEvent
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Mon May 25 02:35:09 GMT+03:30 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:344)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:836)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579)
...
5-May-2015 02:35:11.127 WARNING [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.doClose Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Mon May 25 02:35:09 GMT+03:30 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:357)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:877)
UPDATE
Encountered the same problem. It was caused by using java 8 in combination with some spring dependencies. Haven't figured it out which, but using java 7 solved the problem at the time.
Deploy right version of spring and its dependencies with right version of tomcat,
for eg - Spring 3.2 with Jersey 2.22 in Tomcat 8 and not in tomcat 7.
Spring 3.0 with Jersey 2 in tomcat 7
See the version compatibility
You can have this error if you use Spring and you add an External Jar manually in the project properties instead of using the dedicated dependency file "pom.xml".
For me it was caused by a dependency which introduced an incompatible dependency. I had to exclude the unnecessary root dependencies:
<exclusions>
<!-- Otherwise, Webapp doesn't start up -->
<exclusion>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
</exclusion>
</exclusions>
I was using older version of Tomcat for my project and I was getting same error. I updated it to Tomcat 9 and its working fine now. You should update version as per compatibility of those systems with each other.
Removing and re adding the project in the server helped me to solve the issue
I also ran into this exception recently. For me it was happening when trying to deploy a spring pod in a kubernetes cluster, the pod was being killed before spring had a chance to boot up properly and start responding to the health check.
The fix for me was just to increase the delay before checking the healthcheck endpoint.
It may be worth checking if something is killing spring during startup if you're seeing this error
I came across this exception and in my case the solution was fixing a typo in a #Repository("the typo was here") tag in one of mine DAO implementations
I want to use Mojarra 2.1 with Tomcat 7,
so I added following dependencies in my pom file:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.2</version>
</dependency>
However, when I tried to start Tomcat, I got following exception:
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8007]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
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:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
... 9 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
... 11 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myapp]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
... 14 more
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2820)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1150)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at com.sun.faces.config.FacesInitializer.<clinit>(FacesInitializer.java:107)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.java:1543)
at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1466)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1285)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:896)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:322)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
... 17 more
How is this caused and how can I solve it?
Here's my web.xml file which may contain the cause of the problem:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>appName</display-name>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:META-INF/spring/context.xml
classpath:META-INF/spring/security.xml
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>customers</welcome-file>
</welcome-file-list>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
I have the same problem as you and found out that change from servlet-api to javax.servlet.api will fix the problem. Hope this help. Please note that, I am using Juno Eclipse, Tomcat 7, Dynamic Web Module 3.0, and JDK 1.7.
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
I have the same problem, and it seams somehow to
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
or
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
after setting them to scope provides (or delete them at all when you start an server in maven test) it starts working for me.
#See this Blog: java.lang.ClassFormatError : Absent Code attribute in method that is not native or abstract in class file … - It discuss the problem for javax.persistence.GenerationType but I think you and I hit the same problem.
Change:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.2</version>
</dependency>
To:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.1.6</version>
</dependency>
This workaround fixed it for me:
https://rogerkeays.com/java-lang-classformaterror-exception-with-eclipselink-static-weaving-solved
I traded to glassfish-embedded-all and resolved this.
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2.2</version>
<scope>provided</scope>
</dependency>