We had a male cat that would spray around the house.
The vet would give him female hormone injections every 3-4 months, and that would stop the problem.