spring+4+configuration+annotation
Click here to download eclipse supported ZIP file
This is DemoManager.java file having the source code to execute business logic.
  
  
 
    
package com.cv.spring.core.beans; 
/** 
* @author Chandra Vardhan 
*/ 
public interface DemoManager { 
  public String getServiceName(); 
}  | 
 
    
 
This is DemoManagerImpl.java file having the source code to execute business logic.
  
  
 
    
package com.cv.spring.core.beans; 
 
 
/** 
* @author Chandra Vardhan 
*/ 
public class DemoManagerImpl implements DemoManager { 
  @Override 
  public String getServiceName() { 
    return "My first service with Spring 3"; 
  } 
}  | 
 
    
 
This is ApplicationConfiguration.java file having the source code to execute business logic.
  
  
 
    
package com.cv.spring.core.config; 
 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
 
import com.cv.spring.core.beans.DemoManager; 
import com.cv.spring.core.beans.DemoManagerImpl; 
/** 
* @author Chandra Vardhan 
*/ 
@Configuration 
public class ApplicationConfiguration { 
 
  @Bean(name = "demoService") 
  public DemoManager demoService() { 
    return new DemoManagerImpl(); 
  } 
 
}  | 
 
    
 
This is MainApplication.java file having the source code to execute business logic.
  
  
 
    
package com.cv.spring.core.verify; 
 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.annotation.AnnotationConfigApplicationContext; 
import com.cv.spring.core.beans.DemoManager; 
import com.cv.spring.core.config.ApplicationConfiguration; 
 
/** 
* @author Chandra Vardhan 
*/ 
public class MainApplication { 
  public static void main(String[] args) { 
    ApplicationContext context = new AnnotationConfigApplicationContext( 
        ApplicationConfiguration.class); 
    DemoManager obj = (DemoManager) context.getBean("demoService"); 
    System.out.println(obj.getServiceName()); 
  } 
}  | 
 
    
 
This is pom.xml file having the entries of dependency jars and information to build the application .
	  | <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/xsd/maven-4.0.0.xsd">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.cv.spring</groupId>
	<artifactId>Spring4ConfigurationAnnotation</artifactId>
	<packaging>jar</packaging>
	<version>1.0.0</version>
	<name>Spring4ConfigurationAnnotation Maven Webapp</name>
	http://maven.apache.org
	<properties>
		<springframework.version>4.2.0.RELEASE</springframework.version>
	</properties>
	<dependencies>
		
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${springframework.version}</version>
		</dependency>
		
		
		<dependency>
			<groupId>javax.validation</groupId>
			<artifactId>validation-api</artifactId>
			<version>1.1.0.Final</version>
		</dependency>
		
	</dependencies>
	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>3.1</version>
					<configuration>
						<source>1.8</source>
						<target>1.8</target>
					</configuration>
				</plugin>
				
			</plugins>
		</pluginManagement>
		<finalName>Spring4ConfigurationAnnotation</finalName>
	</build>
</project>  | 
 
This is log4j.properties file having the entries for logging the information into the console/file. 
 #By default enabling Console appender # Root logger option log4j.rootLogger=INFO, stdout
  # 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=%-5p [%c]:%L -->> %m%n
  # Redirect log messages to a log file #log4j.appender.file=org.apache.log4j.RollingFileAppender #log4j.appender.file.File=C:\servlet-application.log #log4j.appender.file.MaxFileSize=5MB #log4j.appender.file.MaxBackupIndex=10 #log4j.appender.file.layout=org.apache.log4j.PatternLayout #log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  | 
 
 
No comments:
Post a Comment