Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Now the database is initialized when you start the application and no…

… users are available yet.
  • Loading branch information...
commit 4761c7e84213f1d67ed4f84024e42abd58f30baa 1 parent 40ab506
@jettro jettro authored
View
4 README
@@ -24,8 +24,8 @@ Running the sample
> mvn clean install
> cd web-ui
> mvn jetty:run-war
-- Browse to : http://localhost:8080/data/init (need to do this once or for a clean start)
-- Browse to http://localhost:8080 and you should see the user account that you can use to login.
+- Browse to http://localhost:8080 and you should see the user accounts that you can use to login.
+(You can always refresh the data by calling /data/init on the application)
Advanced configuration
----------------------
View
9 .../java/org/axonframework/samples/trader/webui/init/CloudApplicationContextInitializer.java
@@ -22,11 +22,10 @@
import org.springframework.context.ConfigurableApplicationContext;
/**
- * Class used by the spring container to set the active profile. The profiles are used to set environment specific
- * beans like the mongo factory for connecting to the mongo database.
- * <p/>
- * We detect whether we can find an active CloudFoundry environment, if so we set the cloud profile as the active
- * profile. If not, we set the default profile as the active one.
+ * <p>Class used by the spring container to set the active profile. The profiles are used to set environment specific
+ * beans like the mongo factory for connecting to the mongo database.</p>
+ * <p>We detect whether we can find an active CloudFoundry environment, if so we set the cloud profile as the active
+ * profile. If not, we set the default profile as the active one.</p>
*
* @author Jettro Coenradie
*/
View
1  web-ui/src/main/java/org/axonframework/samples/trader/webui/init/MongoController.java
@@ -78,7 +78,6 @@ public String collection(@PathVariable("id") String collectionName,
@RequestMapping(value = "/init", method = RequestMethod.GET)
public String initializeMongo(Model model) {
- // TODO jettro: I just do not want to enable this by default. Need to think of something
dbInit.createItems();
model.addAttribute("info", "Mongo database is initialized.");
View
50 ...src/main/java/org/axonframework/samples/trader/webui/init/RunDBInitializerWhenNeeded.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.webui.init;
+
+import org.axonframework.samples.trader.query.users.UserEntry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Component;
+
+/**
+ * <p>Special class used to initialize the database when starting the container. The database is only initialized
+ * when the collection "UserEntry" is not yet available.</p>
+ * <p>We need to check for the display name of the application context since we by default have two using spring-mvc
+ * the way we do.</p>
+ *
+ * @author Jettro Coenradie
+ */
+@Component
+public class RunDBInitializerWhenNeeded implements ApplicationListener<ContextRefreshedEvent> {
+ private static final Logger logger = LoggerFactory.getLogger(RunDBInitializerWhenNeeded.class);
+
+ @Override
+ public void onApplicationEvent(ContextRefreshedEvent event) {
+ DBInit init = event.getApplicationContext().getBean(DBInit.class);
+ MongoTemplate mongoTemplate = event.getApplicationContext().getBean(MongoTemplate.class);
+
+ if ("Root WebApplicationContext".equals(event.getApplicationContext().getDisplayName())) {
+ if (!mongoTemplate.collectionExists(UserEntry.class)) {
+ init.createItems();
+ logger.info("The database has been created and refreshed with some data.");
+ }
+ }
+ }
+}
View
13 web-ui/src/main/resources/log4j.properties
@@ -19,14 +19,13 @@ log4j.appender.Stdout.layout.conversionPattern=%-5p - %-10.10t - %-26.26c{1} - %
log4j.rootLogger=WARN,Stdout
-log4j.logger.org.axonframework=INFO
-log4j.logger.org.axonframework.examples=INFO
+log4j.logger.org.axonframework=WARN
log4j.logger.org.axonframework.samples=INFO
log4j.logger.org.axonframework.saga=INFO
log4j.logger.org.axonframework.samples.trader.app.command.trading=DEBUG
-log4j.logger.org.springframework=INFO
-log4j.logger.org.springframework.security=INFO
-log4j.logger.org.springframework.web.filter=INFO
-log4j.logger.org.springframework.validation.Validator=DEBUG
-log4j.logger.org.springframework.validation=DEBUG
+log4j.logger.org.springframework=WARN
+log4j.logger.org.springframework.security=WARN
+log4j.logger.org.springframework.web.filter=WARN
+log4j.logger.org.springframework.validation.Validator=WARN
+log4j.logger.org.springframework.validation=WARN
Please sign in to comment.
Something went wrong with that request. Please try again.