63 lines
2.7 KiB
Java
63 lines
2.7 KiB
Java
package ch.psi.daq.rest;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
import org.springframework.boot.context.web.SpringBootServletInitializer;
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
import org.springframework.context.annotation.Import;
|
|
|
|
import ch.psi.daq.cassandra.config.CassandraConfig;
|
|
|
|
/**
|
|
* Entry point to our rest-frontend of the Swissfel application which most importantly wires all the @RestController annotated classes.
|
|
* <p>
|
|
*
|
|
* This acts as a @Configuration class for Spring. As such it has @ComponentScan
|
|
* annotation that enables scanning for another Spring components in current
|
|
* package and its subpackages.
|
|
* <p>
|
|
* Another annotation is @EnableAutoConfiguration which tells Spring Boot to run
|
|
* autoconfiguration.
|
|
* <p>
|
|
* It also extends SpringBootServletInitializer which will configure Spring
|
|
* servlet for us, and overrides the configure() method to point to itself, so
|
|
* Spring can find the main configuration.
|
|
* <p>
|
|
* Finally, the main() method consists of single static call to
|
|
* SpringApplication.run().
|
|
* <p>
|
|
* Methods annotated with @Bean are Java beans that are
|
|
* container-managed, i.e. managed by Spring. Whenever there are @Autowire, @Inject
|
|
* or similar annotations found in the code (which is being scanned through the @ComponentScan
|
|
* annotation), the container then knows how to create those beans and inject
|
|
* them accordingly.
|
|
*/
|
|
@SpringBootApplication
|
|
//@Import(CassandraConfig.class) // either define the context to be imported, or see ComponentScan comment below
|
|
@ComponentScan(basePackages = {
|
|
"ch.psi.daq.rest",
|
|
"ch.psi.daq.cassandra.config", // define the package name with the CassandraConfig configuration, or @Import it (see above)
|
|
"ch.psi.daq.cassandra.reader",
|
|
"ch.psi.daq.cassandra.writer"
|
|
})
|
|
public class DaqRestApplication extends SpringBootServletInitializer {
|
|
|
|
|
|
public static void main(final String[] args) {
|
|
SpringApplication.run(DaqRestApplication.class, args);
|
|
}
|
|
|
|
@Override
|
|
protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
|
|
return application.sources(DaqRestApplication.class);
|
|
}
|
|
|
|
// a nested configuration
|
|
// this guarantees that the ordering of the properties file is as expected
|
|
// see: https://jira.spring.io/browse/SPR-10409?focusedCommentId=101393&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-101393
|
|
// @Configuration
|
|
// @Import(CassandraConfig.class)
|
|
// static class InnerConfiguration { }
|
|
}
|