diff --git a/src/main/java/ch/psi/daq/rest/RestApplication.java b/src/main/java/ch/psi/daq/rest/RestApplication.java index 10d391f..172290e 100644 --- a/src/main/java/ch/psi/daq/rest/RestApplication.java +++ b/src/main/java/ch/psi/daq/rest/RestApplication.java @@ -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. - *
- * - * 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. - *
- * Another annotation is @EnableAutoConfiguration which tells Spring Boot to run autoconfiguration. - *
- * 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. - *
- * Finally, the main() method consists of single static call to SpringApplication.run(). - *
- * 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 {
diff --git a/src/main/java/ch/psi/daq/rest/config/RestConfig.java b/src/main/java/ch/psi/daq/rest/config/RestConfig.java
index a9e73a5..caba027 100644
--- a/src/main/java/ch/psi/daq/rest/config/RestConfig.java
+++ b/src/main/java/ch/psi/daq/rest/config/RestConfig.java
@@ -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