In the 17th century Spain was ruled the last 3 monarch of the Habsurg dinasty. It was the end of Spanish hegemony and the kings were not interested in politics so they left the government in hands of validos or prime ministers.
PHILIP III (1598-1621)
Moriscos were a focus of insurrection during Philip II reign and they were accused of having fake conversions and practising Islamic rituals in secret. Philip III expelled them from Spain. This had a negative impact on Spanish economy as agricutlure and craftmenship in Aragón and Valencia as they became deserted and economy collapsed.
The Duke of Lerma was appointed valido and was who effectively ruled the country. In his own interest he moved the capital from Madrid to Valladolid (1601-1606) and it was a very lucrativa bussiness for Lerma as well as for Castilian economy.
By the influence of the Duke of Lerma, Philip III signed peace treaties with England.(Treaty of London 1604)
The Peace with France was signed in 1598 in Vervins before Philip ´s II death.
They also signed the 12 Years Truce with the Netherlands.
The kingdom was at peace for more than 20 years with all these treaties.
PHILIP IV (1521-1665)
The government was in hands of Count-Duke of Olivares. Count-Duke of Olivares wanted all the kingdoms to contribute the same to the army and to pay the expenses of the war.
As a consequence of these measures, Portugal and Catalonia revolted against Castile. Portugal became independent from Spain in 1667 after a long war. Catalonia revolted in 1640 and Catalonian nobles became fonder of France so Catalonia was part of that country until 1652 when Castilians reconquered it and was reintegrated to the Spanish Crown.
In 1621 the Truce of the Twelve Years with the Netherlands expired so Count – Duke of Olivares renewed the conflict with them. On the other hand, Spain was involved in the Thirty Years War supporting the Habsburgs in Germany .
Spain signed the Peace of Westphalia which granted the Netherlands their independence as well as Spain had to cede some possesions to France.
However, the confrontation with France continued until 1659 when Philip IV and Louis XIV signed the Peace of the Pyrenees.
Charles II (1665-1700)
Charles II was three years old when his father died. So his reign started with the regency of his mother Queen Mariana of Habsburg. Later on some validos ( Fernando de Valenzuela, Juan José de Austria, among them) took the government and introduced some reforms to recover the economy.
Conflicts with Portugal continued and the country became definitely independent from Spain by the Treaty of Lisbon. The war with France persisted and Spain was forced to cede to France the Franche – Comté and territories in the Spanish Netherlands as a consequences of the Treaties of Nijmegen (1678).
By the Treaty of Ryswick , and Spain recovered Catalonia and the fortresses of Mons, Luxembourg, and Kortrijk.
Charles II died childless in 1700 and he name Philip of Anjou as his successor.