While you can use your passport that is valid for the whole period to go through immigration in Spain you should be aware that some airlines have different requirements for them to allow you on board of their aircrafts.
Just because the immigration law says one thing not all airlines have the same rules.
Example as a german citizen you can enter spain with a passport that is expired less than 1 year, however an airline can refuse you because their rules say it needs to be 6 month valid. It's contradicting but possible.
So check with your airline before you go.