You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We also need to create an `application.properties` file in `src/main/resources`. We need
200
-
to configure two properties in `application.properties`: We need to set the application
201
-
name (which is translated to the task name), and we need to set the logging for Spring
202
-
Cloud Task to `DEBUG` so that we can see what's going on. The following example shows how
203
-
to do both:
110
+
Now we can open the `application.properties` file in `src/main/resources`.
111
+
We need to configure two properties in `application.properties`:
112
+
113
+
* `application.name`: To set the application name (which is translated to the task name)
114
+
* `logging.level`: To set the logging for Spring Cloud Task to `DEBUG` in order to
115
+
get a view of what is going on.
116
+
117
+
The following example shows how to do both:
118
+
204
119
205
120
[source]
206
121
----
@@ -217,24 +132,23 @@ default, it imports an additional configuration class (`SimpleTaskConfiguration`
217
132
additional configuration registers the `TaskRepository` and the infrastructure for its
218
133
use.
219
134
220
-
Out of the box, the `TaskRepository` uses an in-memory `Map` to record the results
221
-
of a task. A `Map` is not a practical solution for a production environment, since
222
-
the `Map` goes away once the task ends. However, for a quick getting-started
223
-
experience, we use this as a default as well as echoing to the logs what is being updated
135
+
In our demo, the `TaskRepository` uses an embedded H2 database to record the results
136
+
of a task. This H2 embedded database is not a practical solution for a production environment, since
137
+
the H2 DB goes away once the task ends. However, for a quick getting-started
138
+
experience, we can use this in our example as well as echoing to the logs what is being updated
224
139
in that repository. In the <<features-configuration>> section (later in this
225
140
documentation), we cover how to customize the configuration of the pieces provided by
226
141
Spring Cloud Task.
227
142
228
143
When our sample application runs, Spring Boot launches our `HelloWorldCommandLineRunner`
229
-
and outputs our "`Hello, World!`" message to standard out. The `TaskLifecyceListener`
144
+
and outputs our "`Hello, World!`" message to standard out. The `TaskLifecycleListener`
230
145
records the start of the task and the end of the task in the repository.
231
146
232
147
[[getting-started-main-method]]
233
148
==== The main method
234
149
235
150
The main method serves as the entry point to any java application. Our main method
236
-
delegates to Spring Boot's `SpringApplication` class. You can read more about it in the
237
-
Spring Boot documentation.
151
+
delegates to Spring Boot's https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-spring-application.html[SpringApplication] class.
238
152
239
153
[[getting-started-clr]]
240
154
==== The CommandLineRunner
@@ -266,25 +180,32 @@ $ mvn clean spring-boot:run
266
180
....... . . . (Maven log output here)
267
181
....... . . .
268
182
269
-
270
183
. ____ _ __ _ _
271
184
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
272
185
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
273
186
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
274
187
' |____| .__|_| |_|_| |_\__, | / / / /
275
188
=========|_|==============|___/=/_/_/_/
276
-
:: Spring Boot :: (v1.3.3.RELEASE)
277
-
278
-
2016-01-25 11:08:10.183 INFO 12943 --- [ main] com.example.SampleTask : Starting SampleTask on Michaels-MacBook-Pro-2.local with PID 12943 (/Users/mminella/Documents/IntelliJWorkspace/spring-cloud-task-example/target/classes started by mminella in /Users/mminella/Documents/IntelliJWorkspace/spring-cloud-task-example)
279
-
2016-01-25 11:08:10.185 INFO 12943 --- [ main] com.example.SampleTask : No active profile set, falling back to default profiles: default
280
-
2016-01-25 11:08:10.226 INFO 12943 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a2c3676: startup date [Mon Jan 25 11:08:10 CST 2016]; root of context hierarchy
281
-
2016-01-25 11:08:11.051 INFO 12943 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-07-23 17:44:34.426 INFO 1978 --- [ main] i.s.d.helloworld.HelloworldApplication : Starting HelloworldApplication on Glenns-MBP-2.attlocal.net with PID 1978 (/Users/glennrenfro/project/helloworld/target/classes started by glennrenfro in /Users/glennrenfro/project/helloworld)
192
+
2018-07-23 17:44:34.430 INFO 1978 --- [ main] i.s.d.helloworld.HelloworldApplication : No active profile set, falling back to default profiles: default
193
+
2018-07-23 17:44:34.472 INFO 1978 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1d24f32d: startup date [Mon Jul 23 17:44:34 EDT 2018]; root of context hierarchy
2018-07-23 17:44:35.525 INFO 1978 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [org/springframework/cloud/task/schema-h2.sql]
200
+
2018-07-23 17:44:35.558 INFO 1978 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [org/springframework/cloud/task/schema-h2.sql] in 33 ms.
201
+
2018-07-23 17:44:35.728 INFO 1978 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
202
+
2018-07-23 17:44:35.730 INFO 1978 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
203
+
2018-07-23 17:44:35.733 INFO 1978 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
204
+
2018-07-23 17:44:35.738 INFO 1978 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2018-07-23 17:44:35.772 INFO 1978 --- [ main] i.s.d.helloworld.HelloworldApplication : Started HelloworldApplication in 1.625 seconds (JVM running for 4.764)
283
207
Hello, World!
284
-
2016-01-25 11:08:11.071 INFO 12943 --- [ main] com.example.SampleTask : Started SampleTask in 1.095 seconds (JVM running for 3.826)
285
-
2016-01-25 11:08:11.220 INFO 12943 --- [ Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a2c3676: startup date [Mon Jan 25 11:08:10 CST 2016]; root of context hierarchy
286
-
2016-01-25 11:08:11.222 INFO 12943 --- [ Thread-1] o.s.c.t.r.support.SimpleTaskRepository : Updating: TaskExecution{executionId=0, externalExecutionID='null', exitCode=0, taskName='application', startTime=Mon Jan 25 11:08:11 CST 2016, endTime=Mon Jan 25 11:08:11 CST 2016, statusCode='null', exitMessage='null', arguments=[]}
287
-
2016-01-25 11:08:11.222 INFO 12943 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
208
+
2018-07-23 17:44:35.782 DEBUG 1978 --- [ main] o.s.c.t.r.support.SimpleTaskRepository : Updating: TaskExecution with executionId=1 with the following {exitCode=0, endTime=Mon Jul 23 17:44:35 EDT 2018, exitMessage='null', errorMessage='null'}
288
209
----
289
210
290
211
The preceding output has three lines that of interest to us here:
0 commit comments