Monaco, Cyprus, Malta, Gibraltar, Isle of Man, Guernsey, UK non-dom, and the list goes on.
There is an easy solution: don't buy real estate in Spain.
There are many countries that ACTIVELY discourage you from buying real estate. Switzerland for example will ask you to pay TAX for POTENTIAL...