Monday, 16 April 2018

Logging in Spring

                      Logging in Spring


Logging is a very important dependency for Spring because a) it is the only mandatory external dependency, b) everyone likes to see some output from the tools they are using, and c) Spring integrates with lots of other tools all of which have also made a choice of logging dependency. One of the goals of an application developer is often to have unified logging configured in a central place for the whole application, including all external components. This is more difficult than it might have been since there are so many choices of logging framework.

The mandatory logging dependency in Spring is the Jakarta Commons Logging API (JCL). We compile against JCL and we also make JCL Log objects visible for classes that extend the Spring Framework.
he nice thing about commons-logging is that you don’t need anything else to make your application work. It has a runtime discovery algorithm that looks for other logging frameworks in well known places on the classpath and uses one that it thinks is appropriate (or you can tell it which one if you need to). If nothing else is available you get pretty nice looking logs just from the JDK (java.util.logging or JUL for short).
 
<dependencies>
   <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>3.1.2.RELEASE</version>
      <scope>runtime</scope>
      <exclusions>
         <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
         </exclusion>
      </exclusions>
   </dependency>
</dependencies>

Saturday, 17 February 2018

What is @Override in Spring

             What is @Override in Spring




1)If programmer makes any mistake such as wrong method name, wrong parameter types while overriding, you would get a compile time error.

2)It improves the readability of the code.


ApplicationContext

                       ApplicationContext



The ApplicationContext is the central interface within a Spring application for providing configuration information to the application. It is read-only at run time, but can be reloaded if necessary and supported by the application. A number of classes implement the ApplicationContext interface, allowing for a variety of configuration options and types of applications.

                                                    1) One Way

package com.springpg;

import org.springframework.context.support.GenericXmlApplicationContext;

public class Test {

public static void main(String[] args) {
// TODO Auto-generated method stub
GenericXmlApplicationContext cn = new GenericXmlApplicationContext("NewFile.xml");
Classpg obj = cn.getBean("helloWorld",Classpg.class);
obj.show();
}
}


2) Second Way
package com.springpg;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {

public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext("NewFile.xml");
Classpg obj = (Classpg) context.getBean("helloWorld");
obj.show();

}

}

Introduction of Spring technology

            Introduction of Spring technology

 

The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE (Enterprise Edition) platform. Although the framework does not impose any specific programming model, it has become popular in the Java community as an addition to, or even replacement for the Enterprise JavaBeans (EJB) model. The Spring Framework is open source.

Logging in Spring

                      Logging in Spring Logging is a very important dependency for Spring because a) it is the only mandatory external de...