Skip to content

ReporterRestService

kable08 edited this page Jan 24, 2016 · 3 revisions

Topics related to Rest Services.

  • Load Time Weaving - I am explaining the concept with an Spring boot example, however, it can be generalize for other cases also. When we write a spring boot application, it instantiates all beans of type CommandLineRunner. Let's look at an example :

public class Application {

@Bean
CommandLineRunner init(AccountRepository accountRepository,
		BookmarkRepository bookmarkRepository) {
	return (evt) -> Arrays.asList(
			"jhoeller,dsyer,pwebb,ogierke,rwinch,mfisher,mpollack,jlong".split(","))
			.forEach(
					a -> {
						Account account = accountRepository.save(new Account(a,
								"password"));
						bookmarkRepository.save(new Bookmark(account,
								"http://bookmark.com/1/" + a, "A description"));
						bookmarkRepository.save(new Bookmark(account,
								"http://bookmark.com/2/" + a, "A description"));
					});
}

public static void main(String[] args) {
	SpringApplication.run(Application.class, args);
}

}

Here, init method arguments will be instantiated before spring application starts. Now, both the arguments passed in the init function, AccountRepository and BookmarkRepository, are interfaces. But we are using the objects like a normal class. That is because, spring creates proxy classes for the repositories and initialize their beans. This concept is known as Load Time weaving. Other points of interest are Compile Team weaving and Runtime Weaving.

Clone this wiki locally