Mexican–American War from the war of independence (1810–1821) as a weak and divided force. Before the war with the United States, the military faced both internal and foreign challenges. The Spanish still occupied the coastal fortress of San Juan de Ulúa, and Spain did not recognize Mexico's independence, so that the new nation was at risk for invasion. In 1829, the Spanish attempted to reconquer their former colony and Antonio López de Santa Anna became a national hero defending the homeland. The army had a set of privileges ("fueros"), established in the colonial era, that gave it jurisdiction over many aspects of
Historiography of Colonial Spanish America disdain. An important example is Mexico's conservative politician and intellectual Lucas Alamán. His five-volume "Historia de Mejico" is the country's first history, covering the colonial era up to and including the struggle for independence. Alamán viewed crown rule during the colonial era as ideal, and political independence that after the brief monarchy of Agustín de Iturbide, the Mexican republic was characterized by liberal demagoguery and factionalism. Writing in the mid-nineteenth century, Mexican liberal Vicente Riva Palacio, grandson of insurgent hero Vicente Guerrero, wrote a five-volume history of the colonial era from a liberal viewpoint, During the era of Porfirio Díaz