Tuesday, 23 August 2016

Please initialize the log4j system properly.

Eroor :

log4j:WARN No appenders could be found for logger (com.group.api.EmployeeService).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Solution :
1. In maven based. create log4j.properties file in folder /src/main/resources.
2. add following lines.

# Root logger option
log4j.rootLogger=DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n



Monday, 22 August 2016

Failed to load class "org.slf4j.impl.StaticLoggerBinder".

Logging.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Solution :

1. Inlcude the following maven dependency.
       
       <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-api</artifactId>
   <version>1.7.21</version>
</dependency>
    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>1.7.21</version>
</dependency>




Sunday, 21 August 2016

The ResourceConfig instance does not contain any root resource classes

When created a  maven web project.
1. Make sure to delete all the jsp file. 
2. Refresh and build

Method 2 :
1. In eclipse right click go to properties
2. Go ro java build path
3. Order and export
4. Add "JRE and system library","Maven library". and click ok
5. Right click on project
5.1 Go to run.
5.2 maven install.

Thursday, 7 July 2016

spring jersey intigration

steps 1 :

in web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
  <display-name>Archetype Created Web Application</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>\WEB-INF\ApplicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>jerseyService</servlet-name>
<servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.spi.spring.container.servlet.SpringServlet</param-name>
<param-value>com.jersey.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jerseyService</servlet-name>
<url-pattern>/v1/*</url-pattern>
</servlet-mapping>

</web-app>

step 2: application context in web-inf folder.
include namepace for spring module.
ref : http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/xsd-config.html

<?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:context="http://www.springframework.org/schema/context"
 
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd " >

<context:component-scan base-package="com.jersey.api" />

 
</beans>

step 3: configure pom with spring,spring-jersey depencdency

<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">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myjersey</groupId>
  <artifactId>Onejersey</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Onejersey Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <properties>
  <jersey.spring>1.9</jersey.spring>
  </properties>
 




  <dependencies>


  <!-- spring  -->
 
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>4.1.4.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-beans</artifactId>
   <version>4.1.3.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>4.1.3.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-web</artifactId>
   <version>4.1.3.RELEASE</version>
</dependency>


 

  <!-- spring  -->


  <!-- jersey  -->
  <dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-server</artifactId>
   <version>1.9</version>
</dependency>
<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-json</artifactId>
   <version>1.9</version>
</dependency>
<dependency>
   <groupId>com.sun.jersey.contribs</groupId>
   <artifactId>jersey-multipart</artifactId>
   <version>1.9</version>
</dependency>


  <!-- jersey -->
 
    <!-- spring-jersey  -->
  <dependency>
   <groupId>com.sun.jersey.contribs</groupId>
   <artifactId>jersey-spring</artifactId>
   <version>${jersey.spring}</version>
   <exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
   
   </exclusions>
</dependency>

<!-- jackson -jaxrs  -->
<dependency>
   <groupId>com.fasterxml.jackson.jaxrs</groupId>
   <artifactId>jackson-jaxrs-json-provider</artifactId>
   <version>2.5.5</version>
</dependency>
<!-- jackson -jaxrs  -->


    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>Onejersey</finalName>
  </build>
</project>






step 4 : java application



/**
 *
 */
package com.jersey.api;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;

import org.springframework.stereotype.Service;

/**
 * @author voice
 *
 */
@Service
@Path("/hello")
public class Employee {

@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response helloWorld(){
ResponseBuilder rs = Response.status(Status.OK);
System.out.println("HI this is jagdeesh");
return rs.build();
}

}





ref :
spring-jersey
spring module

Saturday, 2 July 2016

difference betweeh length and length() in java

difference betweeh length and length() in java

description : To find the length of array we use legth.

ex : define and intiger array and find the length of the array.
int[] number =  new int[3];
number[0] = 1;
number[1] = 3;
number[2] = 5;

int secondHighest = number.length;
output : 3

description : To find the length of string we use legth().

String name = "voice";
System.out.println(name.length() + " length");

output : 5

Friday, 1 July 2016

Several ports (8005, 8080, 8009) required by Tomcat Server at localhost are already in use


Several ports (8005, 8080, 8009) required by Tomcat Server at localhost are already in use

do : netstat -a -o -n

kill process id : taskkill /F /PID 6532

ref : stackoverflow

Wednesday, 29 June 2016

RDS in aws.

RDS in aws.

Three steps to launch mysql on RDS.
1.Launch.
2.Connect.
3.Manage and moniter.

step 1. launch
a. create db instance.
b. Select engine :
Select db instance from option ex : here we choose mysql from option. (amazon aurora/mariadb/postgresql/oracle/sqlserver).
c. Production :
DEV/test (mysql/amazon aurora).
d. specify db details.
click on (Only show options that are eligible for RDS Free Tier) its a db.t2.micro instance.
select :
DB Instance Identifier* : mydbname
Master Username* : myusername
Master Password : mypassword
Confirm Password : mypassword

version : 5.6.29

select default security group:
default
give DB name.

Click on launch.