First thing is to clean up any catsprayed areas - cats will generally spray in an area where they or other cats have already sprayed. Then mix essential oils (around 20 drops to 500ml water, plus juice of a lemon) in a spray bottle, and spray the mixture in areas where you don't want the cat to spray.
You can use essential oils alone or in combination, depending on what you like and the cat doesn't. Good ones to try are: citronella, lemongrass, lavender, teatree, eucalyptus, basil, orange, peppermint and black pepper oils. Don't use ground pepper or mothballs, as some books suggest - these work but can injure the cat, and naphthalene is poisonous to everything. Respray once a week, or after rain if you are using it outdoors.