Monday 26 June 2017

java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()



Exception:
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:304)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4901)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5188)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)


Solution :


This error usual means that you have a both a JAX-RS 1 and JAX-RS 2 jar on the classpath. 

Jersey 2 uses JAX-RS 2 (javax.ws.rs-api-2.0.1.jar), but if you have the jsr311-api.jar also, which is JAX-RS 1, there is a javax.ws.rs.core.Application in each jar.

But the jsr311-api Application doesn't have the method getProperties() (hence NoSuchMethodError).

So just exclude these dependencies manually or by eclipse dependency hierarchy feature :

1. Open POM
2. Open dependency hierarchy tab in bottom.
3. search for jsr and exclude all jsr dependencies.







Failed to instantiate [org.apache.cxf.endpoint.Server]: Factory method 'jaxRsServer' threw exception;



Exception:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.cxf.endpoint.Server]: Factory method 'jaxRsServer' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.isCglibProxyClass(Ljava/lang/Class;)Z
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
 at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
 ... 28 more
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.isCglibProxyClass(Ljava/lang/Class;)Z
 at org.apache.cxf.common.util.SpringAopClassHelper.getRealClassInternal(SpringAopClassHelper.java:85)
 at org.apache.cxf.common.util.ClassHelper.getRealClass(ClassHelper.java:55)
 at org.apache.cxf.jaxrs.JAXRSServiceFactoryBean.setResourceClassesFromBeans(JAXRSServiceFactoryBean.java:218)
 at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.setServiceBeans(JAXRSServerFactoryBean.java:302)
 at com.example.config.AppConfig.jaxRsServer(AppConfig.java:29)
 at com.example.config.AppConfig$$EnhancerBySpringCGLIB$$67f4649c.CGLIB$jaxRsServer$3(<generated>)
 at com.example.config.AppConfig$$EnhancerBySpringCGLIB$$67f4649c$$FastClassBySpringCGLIB$$ae89a288.invoke(<generated>)
 at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
 at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
 at com.example.config.AppConfig$$EnhancerBySpringCGLIB$$67f4649c.jaxRsServer(<generated>)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:483)
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(Simpl




 To solve this issue update your versions of below dependencies:

<org.apache.cxf.version>3.1.0</org.apache.cxf.version>

<org.springframework.version>4.3.5.RELEASE</org.springframework.version>

this will resolve the issue,


Thursday 22 June 2017

Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError.

I was hitting the same problem when working with Apache tomcat . .


Solution Steps :


  1. Backup your pom.xml somewhere.
  2. Go to your pom.xml and on the bottom tab and click "Dependency Hierarchy" tab. 
  3. From there search for log4j-over-slf4j. 
  4. Exclude all instances of this dependency (right click on the instance and "Exclude Maven Artifact"). After you have no more log4j-over-slf4j appearing save your POM and try to run the program. 
  5. If it still doesn't work then undo the changes you just made and exclude all instances of slf4j-log4j12.


Hopes this will resolve your problem

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

Problem :

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;


Solution :

getContextPath() was added with Servlet 2.5, does your version of Jetty supports that ? 


Might also want to check that you do not have some older or duplicate version of j2ee around.

Indicates that Jetty 6.1.x supports Servlet 2.5 , make sure you don't have a pre-2.5 servlet version around. If this gets loaded before the 2.5 version, the entire classpath sees only Servlet 2.0 API (the 2.5 doesn't even gets loaded).

so exclude it from the maven pom.xml


Exclusion entry
 <exclusion>
           <artifactId>servlet-api</artifactId>
           <groupId>javax.servlet</groupId>
  </exclusion>

Monday 12 June 2017

Debug javascript.

Guide to Debug your java script files in google Chrome.



Ways to find debug console in chrome.

2. press F12 or inspect element

Below window will open up which contains various tabs.
 
Tab Details:

Elements: it shows HTML part of your page.
console : in case you want to run some statements.
sources : all your JavaScript files.
Network : shows all your Ajax and load requests.
Performance: you can monitor your page performance


How to debug:

To debug any javascript file just search your file by using ctrl+O or select your file from the left panel of your browser window.

To add debug point just click on row number as shown in the image below.


Now perform any operations on you webpage. Here I'm selecting value from the dropdown.






As soon as you select any value from the drop down. your request goes for processing and your request stop on debug point.



For this request in network tab there is an entry for it. which shows data retrieve from the request for more information you can select request header,response and preview tab.

After successful hit of the request your request will enter in the success part of your ajax request.




If you want to change and explore more values you can go to console tab.

if you want to change values of HTML element then go to element tab where you can change style of the page and can see change in real time.





Spring boot with CORS

CORS (Cross-Origin Resource Sharing) errors occur when a web application running in a browser requests a resource from a different domain or...