ATEST-81:
- removing ComponentScan
This commit is contained in:
@ -4,39 +4,17 @@ 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.hazelcast.config.HazelcastClientConfig;
|
||||
import ch.psi.daq.hazelcast.config.HazelcastConfig;
|
||||
|
||||
/**
|
||||
* Entry point to our rest-frontend of the data acquisition (DAQ) 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.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",
|
||||
"ch.psi.daq.hazelcast",
|
||||
"ch.psi.daq.rest",
|
||||
})
|
||||
@Import({HazelcastConfig.class, HazelcastClientConfig.class})
|
||||
public class RestApplication extends SpringBootServletInitializer {
|
||||
|
||||
|
||||
|
@ -1,43 +1,27 @@
|
||||
package ch.psi.daq.rest.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.hazelcast.client.HazelcastClient;
|
||||
import com.hazelcast.client.config.ClientConfig;
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
import com.hazelcast.core.ManagedContext;
|
||||
import com.hazelcast.spring.context.SpringManagedContext;
|
||||
|
||||
import ch.psi.daq.common.statistic.StorelessStatistics;
|
||||
import ch.psi.daq.domain.cassandra.ChannelEvent;
|
||||
import ch.psi.daq.hazelcast.config.HazelcastConfig;
|
||||
import ch.psi.daq.rest.ResponseStreamWriter;
|
||||
import ch.psi.daq.rest.model.PropertyFilterMixin;
|
||||
import ch.psi.daq.rest.response.ResponseStreamWriter;
|
||||
|
||||
@Configuration
|
||||
@PropertySource(value = { "classpath:rest.properties" })
|
||||
@PropertySource(value = { "file:${user.home}/.config/daq/rest.properties" }, ignoreResourceNotFound = true)
|
||||
public class RestConfig {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RestConfig.class);
|
||||
|
||||
// TODO refactor - also defined in HazelcastNodeConfig
|
||||
private static final String HAZELCAST_GROUP_PASSWORD = "hazelcast.group.password";
|
||||
private static final String HAZELCAST_GROUP_NAME = "hazelcast.group.name";
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
@ -45,9 +29,9 @@ public class RestConfig {
|
||||
// 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 { }
|
||||
@Configuration
|
||||
@Import({HazelcastConfig.class})
|
||||
static class InnerConfiguration { }
|
||||
|
||||
@Bean
|
||||
public JsonFactory jsonFactory() {
|
||||
@ -58,40 +42,6 @@ public class RestConfig {
|
||||
public ResponseStreamWriter responseStreamWriter() {
|
||||
return new ResponseStreamWriter();
|
||||
}
|
||||
|
||||
@Bean(name = HazelcastConfig.BEAN_NAME_HAZELCAST_CLIENT)
|
||||
public HazelcastInstance hazelcastClientInstance() {
|
||||
return HazelcastClient.newHazelcastClient(hazelcastClientConfig());
|
||||
}
|
||||
|
||||
private ClientConfig hazelcastClientConfig() {
|
||||
ClientConfig config = new ClientConfig();
|
||||
config.setManagedContext(managedContext());
|
||||
|
||||
config.getNetworkConfig().setAddresses(hazelcastInitialCandidates());
|
||||
|
||||
String groupName = env.getProperty(HAZELCAST_GROUP_NAME);
|
||||
if (groupName != null) {
|
||||
config.getGroupConfig().setName(groupName);
|
||||
}
|
||||
String groupPassword = env.getProperty(HAZELCAST_GROUP_PASSWORD);
|
||||
if (groupPassword != null) {
|
||||
config.getGroupConfig().setPassword(groupPassword);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
private ManagedContext managedContext() {
|
||||
return new SpringManagedContext();
|
||||
}
|
||||
|
||||
private List<String> hazelcastInitialCandidates() {
|
||||
List<String> clusterMembers = Arrays.asList(StringUtils.commaDelimitedListToStringArray(env.getProperty("hazelcast.initialcandidates")));
|
||||
logger.info("The following hosts have been defined to form a Hazelcast cluster: {}", clusterMembers);
|
||||
return clusterMembers;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
|
@ -27,10 +27,10 @@ import ch.psi.daq.domain.DataType;
|
||||
import ch.psi.daq.domain.cassandra.ChannelEvent;
|
||||
import ch.psi.daq.domain.cassandra.DataEvent;
|
||||
import ch.psi.daq.hazelcast.query.processor.QueryProcessor;
|
||||
import ch.psi.daq.rest.ResponseStreamWriter;
|
||||
import ch.psi.daq.rest.queries.AbstractQuery;
|
||||
import ch.psi.daq.rest.queries.PulseRangeQuery;
|
||||
import ch.psi.daq.rest.queries.TimeRangeQuery;
|
||||
import ch.psi.daq.rest.response.ResponseStreamWriter;
|
||||
|
||||
@RestController
|
||||
public class DaqRestController {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package ch.psi.daq.rest;
|
||||
package ch.psi.daq.rest.response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
@ -1,10 +1,2 @@
|
||||
# port for the Spring boot application's embedded Tomcat server
|
||||
server.port=8080
|
||||
|
||||
# defines the list of hosts who are tried for an initial connection to the cluster
|
||||
#hazelcast.members=sf-nube-11.psi.ch,sf-nube-12.psi.ch,sf-nube-13.psi.ch,sf-nube-14.psi.ch
|
||||
hazelcast.initialcandidates=localhost
|
||||
|
||||
# defines the cluster group and its password
|
||||
hazelcast.group.name=QueryCluster
|
||||
hazelcast.group.password=d9zT5h*4!KAHesxdnDm7
|
||||
|
@ -24,7 +24,7 @@ import ch.psi.daq.test.cassandra.CassandraDaqUnitDependencyInjectionTestExecutio
|
||||
@TestExecutionListeners({
|
||||
CassandraDaqUnitDependencyInjectionTestExecutionListener.class,
|
||||
DependencyInjectionTestExecutionListener.class})
|
||||
@SpringApplicationConfiguration(classes = {RestApplication.class, DaqWebMvcConfiguration.class})
|
||||
@SpringApplicationConfiguration(classes = {RestApplication.class, DaqWebMvcConfig.class})
|
||||
//@EmbeddedCassandra
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@WebAppConfiguration
|
||||
|
@ -9,16 +9,9 @@ import ch.psi.daq.rest.config.RestConfig;
|
||||
import ch.psi.daq.test.cassandra.LocalCassandraTestConfig;
|
||||
|
||||
@Configuration
|
||||
//@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"
|
||||
//})
|
||||
@Import(value = {LocalCassandraTestConfig.class, RestConfig.class})
|
||||
@EnableWebMvc
|
||||
public class DaqWebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
public class DaqWebMvcConfig extends WebMvcConfigurationSupport {
|
||||
|
||||
// add test-specific beans and configurations here
|
||||
}
|
Reference in New Issue
Block a user