In main.clj, it looks like you aren't keeping a reference to the started
app. So when you call stop, you are actually stopping the version of the
system which doesn't have the jetty server set.
Try changing this:
(defn -main [& args]
(component/start app)
(component/stop app))
to this:
(defn -main [& args]
(-> app
(component/start)
(component/stop)))
Now, that will immediately start then stop your app, which isn't useful in
the long run. Here's how I've managed the system in one of my apps:
https://github.com/sashton/event-loupe/blob/master/src/clj/event_loupe/core.clj
And here is how start/stop/restart it in the repl:
https://github.com/sashton/event-loupe/blob/master/repl/user.clj
On Tuesday, February 10, 2015 at 8:35:44 AM UTC-5, Gilberto Garcia wrote:
>
> I get the same error because the key :jetty-server = nil
> so, (:jetty-server this) will return nil
> what turns into (.stop nil)
>
> note that if I print 'this' after assoc'ing :jetty-server in the start
> lifecycle I see the jetty server associated with the key :jetty-server
>
> for some reason I'm loosing the reference for the jetty server between
> start and stop phases.
>
> On Tue, Feb 10, 2015 at 10:35 AM, Chris Ford <[email protected]
> <javascript:>> wrote:
>
>> What happens if you try:
>>
>> (.stop (:jetty-server this))
>>
>> instead of:
>>
>> (.stop jetty-server)
>>
>> I'm not at a repl right now, but maybe your stop method is closing over
>> the value of jetty-server that's passed in when the record was constructed?
>>
>> On 10 February 2015 at 22:58, Gilberto Garcia <[email protected]
>> <javascript:>> wrote:
>>
>>> Here it goes https://gist.github.com/ggarciajr/e5f1c0f1072c63705ac4
>>>
>>> Note that the :jetty-server is nil and it should hold the jetty server
>>> so it can be stopped in the stop phase.
>>>
>>> #toro_tokens_rest.components.ring.Ring{:port 3000, :database
>>> #toro_tokens_rest.components.database.Database{:path /tmp/dev-leveldb},
>>> :jetty-server nil}
>>>
>>> So, I bet I'm doing something wrong.
>>>
>>>
>>> On Tue, Feb 10, 2015 at 9:45 AM, Chris Ford <[email protected]
>>> <javascript:>> wrote:
>>>
>>>> Perhaps it would help if you posted a gist of the stacktrace you
>>>> encounter?
>>>>
>>>> On 10 February 2015 at 20:29, Gilberto Garcia <[email protected]
>>>> <javascript:>> wrote:
>>>>
>>>>> Hi All,
>>>>>
>>>>> I'm new to clojure and I'm trying to create a simple rest api to
>>>>> create and manages to token.
>>>>> I'm trying to use Stuart's component library but I'm having problems
>>>>> when trying to stop a component because one of the component's map
>>>>> attribute is nil, so, when I try to stop the jetty server I get a NPE.
>>>>>
>>>>> I bet that I'm doing something wrong and I'm failing to find what is
>>>>> wrong due to my lack of clojure knowledge/experience.
>>>>>
>>>>> Any help is appreciated.
>>>>>
>>>>> Repo:
>>>>> https://github.com/ggarciajr/toro-tokens-rest/tree/adding-functionality
>>>>> Branch: adding-functionality
>>>>>
>>>>> Thanks in advance
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Clojure" group.
>>>>> To post to this group, send email to [email protected]
>>>>> <javascript:>
>>>>> Note that posts from new members are moderated - please be patient
>>>>> with your first post.
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected] <javascript:>
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/clojure?hl=en
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Clojure" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected] <javascript:>.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to [email protected]
>>>> <javascript:>
>>>> Note that posts from new members are moderated - please be patient with
>>>> your first post.
>>>> To unsubscribe from this group, send email to
>>>> [email protected] <javascript:>
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/clojure?hl=en
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected] <javascript:>.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to [email protected]
>>> <javascript:>
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> [email protected] <javascript:>
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected] <javascript:>.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> <javascript:>
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.