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
Mexican War of Independence of Iguala, Iturbide persuaded Guerrero to join his forces in support of this conservative independence movement. A new army, the Army of the Three Guarantees, was placed under Iturbide's command to enforce the Plan of Iguala. The plan was so broadly based that it pleased both patriots and loyalists. The goal of independence and the protection of Roman Catholicism brought together all factions. Iturbide's army was joined by rebel forces from all over Mexico. When the rebels' victory became certain, the Viceroy resigned. On August 24, 1821, representatives of the Spanish crown and Iturbide signed the Treaty of Córdoba, which