Yes. And it did it: from 1580 to 1640, Portugal was part of the Hispanic Empire.
In 1578 King Sebastian I of Portugal died in battle without children. His successor Henry I died just two years later, in 1580.
Spanish king Phillip II was the son of Charles I of Spain (and V of the HRE) and Elisabeth of Portugal (daughter of king Manuel I of Portugal, and grandmother of Sebastian), which made him a valid candidate. Portuguese Courts were supposed to settle the issue, but Phillip II occupied Portugal militarily.
There was some resistance, but the last pretender, Antonio, was defeated in 1583.
Portugal was incorporated to the Hispanic Empire in a dinastic Union (during the 16th and 17th centuries, the kingdoms in the Hispanic Empire had a great deal of autonomy in internal and financial affairs, with their own legal systems and institutions). Therefore, Portugal maintained its own currency, Courts, laws, rights and privileges.
At the beginning of the 17th century, the "valido" (a sort of Prime Minister) of king Phillip IV, the Count-Duke of Olivares tried to centralise the Empire so that all kingdoms would contribute to the wars of the crown. Most of those kingdoms did not like it. In 1636 France and Spain entered a new war. This meant that an army had to be stationed in Catalonia (which borders France), despite the Catalan Court's negative. The locals, who had to maintain the soldiers, did not like it and accused them of various abuses. A general rebellion started in Catalonia in 1640, and several other minor rebellions started in other regions.
The Spanish king had to request resources from other regions and move more troops to Catalonia to end the revolt.
After sixty years of Spanish rule, the Portuguese nobility is tired of having to pay taxes to fund Spain's wars, and worried about the new attempts to centralise the empire. Now, with the Spanish occupied putting down revolts and fighting against the French, Portugal sees its opportunity. In 1640 the Portuguese Restoration War starts, and in 1664 the Spanish and Portuguese kings sign the Treaty of Lisbon, recognising Portuguese Independence.