Skip to content

Instantly share code, notes, and snippets.

@patelkunal
Last active November 2, 2017 03:34
Show Gist options
  • Save patelkunal/4a55c89fe908e7b2e920897fefa7f010 to your computer and use it in GitHub Desktop.
Save patelkunal/4a55c89fe908e7b2e920897fefa7f010 to your computer and use it in GitHub Desktop.
bootstrap-spring-annotation-based-gradle-application-without-spring-boot
package org.coderearth.springkitchens.mailkitchen;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.util.Properties;
/**
* Created by kunal_patel on 24/10/17.
* SomeBean and SomeAnotherBean are just placeholder to showcase bean creation - replace it with actual stuff.
*/
@Configuration
@ComponentScan(basePackages = "org.coderearth.springkitchens.mailkitchen")
public class AppConfig {
@Bean
public SomeBean createSomeBean() {
return new SomeBean();
}
@Bean
public SomeAnotherBean createSomeAnotherBean(final SomeBean someBeanInstance) {
return new SomeAnotherBean(someBeanInstance);
}
}
group 'org.coderearth.springkitchens'
version '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile("org.springframework:spring-context:4.3.12.RELEASE")
// compile("org.springframework:spring-context-support:4.3.12.RELEASE")
compile("ch.qos.logback:logback-classic:1.1.11")
compile("org.slf4j:jcl-over-slf4j:1.7.25")
testCompile 'junit:junit:4.12'
}
mainClassName = 'org.coderearth.springkitchens.mailkitchen.MainApplication'
package org.coderearth.springkitchens.mailkitchen;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.util.Assert;
public class MainApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(MainApplication.class);
public static void main(String[] args) {
LOGGER.info("Staring up MainApplication !!");
final ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
Assert.notNull(context, "ApplicationContext is not yet initialized !!");
Assert.notNull(context.getBean(SomeBean.class), "SomeBean is not yet initialized !!");
LOGGER.info("Shutting down MainApplication !!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment