I believe "Spanish" music originated from 15th and 16th century music in Spain. The early guitar was a major contributor to this and you hear many "Spanish" styles in classical guitar playing. A Scarlatti Guitar Sonata for example:
Scarlatti has been in Spain and in Portugal. In Portugal he worked with a great portuguese composer, Carlos Seixas (You may wish to see in youtube Carlos Seixas Concert for harpsichord and orchestra in A major,m its amazing). Both Scarlatti and Seixas were inspired by portuguese and spanish popular music. With Bach, that influence seems less probable.