Created
June 13, 2012 14:12
-
-
Save dsyer/2924318 to your computer and use it in GitHub Desktop.
Spring Batch @configuration samples using step scope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*~ | |
#* | |
.#* | |
.gradle | |
*.sw? | |
*.class | |
.classpath | |
.project | |
.settings | |
bin | |
build | |
target | |
*.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GrabConfig(systemClassLoader=true) | |
@Grab("org.springframework:spring-jdbc:4.0.0.BOOTSTRAP-SNAPSHOT") | |
@Grab("org.hsqldb:hsqldb-j5:2.0.0") | |
@Controller | |
class App { | |
@Value('${value:World}') | |
private String value | |
@Autowired | |
private DataSource dataSource | |
@RequestMapping("/") | |
@ResponseBody | |
String home() { | |
println ("********: ${value}, ${dataSource}") | |
return "Hello ${value}!" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
class HadoopConfig implements CommandlineRunner { | |
@Autowired | |
private HadoopConfiguration configuration | |
@Bean | |
JobRunner runner() { | |
JobRunner runner = new JobRunner() | |
runner.jobNames = ["wordcountJob"] | |
runner | |
} | |
@Bean | |
JobFactoryBean wordcountJob() { | |
JobFactoryBean factory = new JobFactoryBean() | |
factory.mapper = "org.apache.hadoop.examples.WordCount.TokenizerMapper" | |
factory.reducer = "org.apache.hadoop.examples.WordCount.IntSumReducer" | |
factory.outputPath = "/user/gutenberg/output" | |
factory.inputPath = ["/user/gutenberg/input"] | |
factory.configuration = configuration | |
factory | |
} | |
@Override | |
void run(String... args) { | |
println "I'm running!" | |
runner().startJobs() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<body> | |
hello, world | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab("org.hsqldb:hsqldb-j5:2.0.0") | |
@EnableBatchProcessing | |
class JobConfig { | |
@Autowired | |
private JobBuilderFactory jobs | |
@Autowired | |
private StepBuilderFactory steps | |
@Bean | |
protected Tasklet tasklet() { | |
return new Tasklet() { | |
RepeatStatus execute(StepContribution contribution, ChunkContext context) { | |
return RepeatStatus.FINISHED | |
} | |
} | |
} | |
@Bean | |
Job job() throws Exception { | |
return jobs.get("job").start(step1()).build() | |
} | |
@Bean | |
protected Step step1() throws Exception { | |
return steps.get("step1").tasklet(tasklet()).build() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
class Min { | |
@RequestMapping("/") | |
@ResponseBody | |
String home() { | |
return "Hello World!" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableWebMvc | |
class WebConfig extends WebMvcConfigurerAdapter { | |
@Override | |
void addResourceHandlers(ResourceHandlerRegistry registry) { | |
registry.addResourceHandler("/**").addResourceLocations("classpath:/public/") | |
} | |
@Override | |
void addViewControllers(ViewControllerRegistry registry) { | |
registry.addViewController("/").setViewName("redirect:index.html") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment