Permalink
Browse files

Introduces Spring framework.

# Pure annotation based dependency management.
# Enhances the code to use multiple dependencies at run time.
  • Loading branch information...
Mohit Chilkoti
Mohit Chilkoti committed Oct 22, 2017
1 parent 8978d5f commit e824f1bdffeb17e1f289f4d2d128ab94d23a8ba8
@@ -1,4 +1,5 @@
apply plugin:'application'
apply plugin: 'eclipse'

sourceSets {
main {
@@ -8,4 +9,16 @@ sourceSets {
}
}

mainClassName = "com.codecramp.HelloGradle"
mainClassName = "com.codecramp.Application"

repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile 'org.springframework:spring-context:5.0.0.RELEASE'
}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,39 @@
package com.codecramp;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.codecramp.greeting.ByeGradle;
import com.codecramp.greeting.CustomGreeting;
import com.codecramp.greeting.Greeting;
import com.codecramp.greeting.HelloGradle;

@Configuration
@ComponentScan
public class Application {

public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(Application.class);
HelloGradle helloGreeting = context.getBean(HelloGradle.class);
ByeGradle byeGreeting = context.getBean(ByeGradle.class);
CustomGreeting customGreeting = context.getBean(CustomGreeting.class);

System.out.println("\n\n");
helloGreeting.greet();
byeGreeting.greet();
customGreeting.greet();
System.out.println("\n\n");

context.close();
}
}





@@ -0,0 +1,12 @@
package com.codecramp.greeting;

import org.springframework.stereotype.Component;

@Component
public class ByeGradle implements Greeting {

@Override
public void greet() {
System.out.println("Bye Gradle!!!");
}
}
@@ -0,0 +1,24 @@
package com.codecramp.greeting;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class CustomGreeting implements Greeting {
private String greeting;
private String greeter;

public CustomGreeting() { }

@Autowired
public CustomGreeting(@Value("Hey There!!!") final String greeting, @Value("Mohit Kumar") final String greeter) {
this.greeting = greeting;
this.greeter = greeter;
}

@Override
public void greet() {
System.out.println(greeting + ", I am - " + greeter);
}
}
@@ -0,0 +1,5 @@
package com.codecramp.greeting;

public interface Greeting {
public void greet();
}
@@ -0,0 +1,12 @@
package com.codecramp.greeting;

import org.springframework.stereotype.Component;

@Component
public class HelloGradle implements Greeting {

@Override
public void greet() {
System.out.println("Hello Gradle!!!");
}
}

0 comments on commit e824f1b

Please sign in to comment.