If you're interested in Italian unification, u/Klesk_vs_Xaero went into great detail about the lead-up to Italian unification here. There is also a three-year old answer by u/kieslowskifan which you can read here here, contextualizing Italian unification within the narrative of post-Napoleonic european consolidation.
The thing about Italian Unification (and I can't say I know as much about Germany beyond some casual reading) is that the movement has its definitive start in the Napoleonic conquest of Italy. While there certainly had been intellectual currents arguing in favor of a unified peninsula, and more than one ruler had designs to crown himself King of Italy (emphasis on designs to crown *himself*, because the last people with a successful plan to govern a united Italy were two women) since the eleventh century no ruler or general, be they Italian or foreign, had been able to unify the peninsula until Napoleon Bonaparte and the French Revolutionary Armies appeared on the scene. Why Italy was fragmented for so long in the first place is another complicated matter; I discuss a bit of that here.
Italy had certainly already been subject to foreign domination long before the napoleonic conquest. In fact, starting in the second half of the the sixteenth century Spanish control over Milan and Naples, the two most powerful Italian states, had pretty much ensured a static balance of power on the peninsula with Spain as hegemon. Although no one dared challenge Spanish power in the Mediterranean, a web of alliances between Italian states and other European powers like France and Austria nonetheless also deterred Spain from acting to aggressively itself. The independent Italian states in turn benefitted from close relationships with foreign powers, with Genoese bankers and merchants ubiquitous in Spanish cities, and Venetian consuls appearing as fixtures in the royal courts in London and Versailles; all working to disincentives drastic changes to the status quo which could shift the balance of power. After all, when Italian monarchs challenged the previous balance of power in the final years of the fifteenth century, the result was foreign intervention and decades of war resulting in the aforementioned conquest of Milan and Naples.
But by the time of the napoleonic wars Spain had been an ailing power for over a century. While I'm not an expert on Spanish history (much less Spain's decline) it is clear that in spite of the early windfalls brought on by conquest and colonization, by the early 18th century the strain of maintaining American colonies and the inflation brought about by an extractive economic policy with little regard to economic development had left Spain unable to effectively oppose and overcome foreign powers. The War of Spanish Succession, which ended in 1715, in addition to blocking a union of the French and Spanish crowns also forced the separation of Spanish and Neapolitan monarchies and the transfer of the Duchy of Milan to Austria, formally ending Spanish hegemony in the Mediterranean. But things continued much as they had done before; with Austria projecting power in the peninsula through it's Milanese possession.
Only the French Emperor Napoleon, through his complete and total conquest of the peninsula, would lay the definitive foundation for what became modern Italy. In spite of the three-way administrative division, Italy was devoid of economic/customs barriers for the first time in hundreds of years. Northwestern Italy was integrated with the French Empire, while the northeast was proclaimed a separate "Kingdom of Italy" with Napoleon as monarch. The south was a little more isolated, and remained the "Kingdom of Naples," ruled by Napoleon’s brother-in-law; Joachim Murat. Nonetheless, in all three polities Napoleon abolished old ecclesiastical and aristocratic privileges and imposed uniform legal, administrative, and fiscal laws and institutions. All three polities were administered by a large and meritocratic governmental bureaucracy. What's more, Napoleon was also a very aggressive secularizer, greatly diminishing the power of the church in favor of his increasingly powerful civil administration.
Although the enthusiasm with which different regions of Italy embraced the Napoleonic reforms differed (French reforms were popular with both the urban and rural populace in Lombardy and Piedmont, but French rule in the south faced stiff popular revolts as well as opposition by the influential, albeit curtailed, clergy) the Italian states reinstated after the Congress of Vienna following Napoleon’s fall can be said to have emerged with a new lease on life, with more or less equal opportunity to shape their destiny. However, in the restoration pretty much all Italian states chose to be repressive and punitive towards those people who had been rewarded under Napoleon's system. Only the government of the Kingdom of Sardinia-Piedmont in Turin soon changed its stance after an initial period of suspicion.
The Piedmontese began welcoming prominent intellectuals and exiles from the rest of Italy. These intellectuals would not only supply the Turinese government with a full roster of capable public administrators, but gradually lobby Piedmontese government and society to take an aggressive stance against foreign powers in Italy and Italian states collaborating with them. Indeed, many intellectual refugees would arrive from Lombardy and Venetia, the two regions that the congress of Vienna had awarded to the Austrian Empire. While Lombardy's tradition of self-government was a distant memory, under the Spanish and Austrian Empires before Napoleon the region had been largely governed by the worldly and diligent Milanese aristocracy. However the Austrian administration's post-napoleonic paranoia pushed prominent aristocratic and bourgeois Lombards alike to undermine Austrian authority (and the sequester of property owned by Lombards spending "extended holidays" in Piedmont when on the run from Austrian authorities would be a recurring point of contention that Piedmontese governments would exploit to drive up tension in the lead-up to war). The Venetians too, although strangely passive in spite of their strong history of independence, were none to happy with being part of a foreign empire. Both the Venetians and Milanese would revolt against Austrian rule in 1848, prompting the first of many Piedmontese interventions against their eastern neighbor culminating in the conquest of the peninsula.
There are many general historical overviews you can look into if you'd like to learn more. A great source is Davis, John A. Italy in the Nineteenth Century, 1796-1900. Oxford: Oxford UP, 2000.