Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

[11:58:46 CDT(-0500)] <fairwinds> serac: hi
[11:58:53 CDT(-0500)] <serac> howdy
[11:59:21 CDT(-0500)] <fairwinds> serac: I have a question about bean initialization and properties
[11:59:32 CDT(-0500)] <serac> shoot
[12:01:11 CDT(-0500)] <fairwinds> k, what I am finding is that if I call a bean within the initialization of another bean I will get a null pointer error
[12:01:43 CDT(-0500)] <serac> Got some source to share?
[12:01:55 CDT(-0500)] <fairwinds> serac: yup. give me a sec to paste something
[12:08:08 CDT(-0500)] <fairwinds> serac: https://gist.github.com/a629b86d095547db5b31
[12:08:24 CDT(-0500)] <fairwinds> serac: I will paste my config
[12:08:54 CDT(-0500)] <serac> Where are you referencing other components in that source that would cause NPE?
[12:08:56 CDT(-0500)] <serac> cf line #
[12:09:32 CDT(-0500)] <fairwinds> just a sec I will get config up so you can see
[12:10:56 CDT(-0500)] <fairwinds> https://gist.github.com/8c502eaeba246c794951
[12:11:09 CDT(-0500)] <fairwinds> one more, give me one more sec
[12:12:36 CDT(-0500)] <fairwinds> https://gist.github.com/1f7baf19bced2a32c2bd
[12:13:55 CDT(-0500)] <fairwinds> serac: k, now that I have stuff there. Line 64 in setDatabase
[12:14:35 CDT(-0500)] <serac> You should not be doing anything other than simple property validation in setters.
[12:14:54 CDT(-0500)] <fairwinds> serac: Yeah, I guess that is my trouble
[12:14:56 CDT(-0500)] <serac> You want to implement InitializingBean and put the stuff that actually creates the connection in the afterPropertiesSet() method.
[12:14:56 CDT(-0500)] <fairwinds> (smile)
[12:15:23 CDT(-0500)] <fairwinds> ah, that is what I was going to ask if there was such a thing
[12:15:27 CDT(-0500)] <serac> So everything after the first line would go in afterPropertiesSet();
[12:15:56 CDT(-0500)] <serac> You must implement InitializingBean to clue Spring in to treat that method specially and invoke it after all beans are wired up.
[12:16:07 CDT(-0500)] <fairwinds> ah, great, you are a wealth of knowledge. I am not a very good Java programmer yet (smile)
[12:16:52 CDT(-0500)] <fairwinds> serac: exactly what I needed to know here
[12:16:54 CDT(-0500)] <serac> Spring is such a superset of Java that it's hardly the same league, so don't be too frustrated with Spring issues like this.

  • No labels