Hello

I read much about marriage with someone illegaly staying in europe.

I'm a german citizen living in germany.

can I come and marry my non-eu boyfriend in spain ?

I read that it's possible only if I become a resident in spain If this is true

How to become a resident in spain ?
and how long does it take until my future husband will have his residence permit ?
and do we have to stay within this period in spain ?
do I need a job or only a rent or both ?

Thank you.