Answer :

The Mexican War: 1846 - 1848

Obviously, the opponent was Mexico. This war (as seen above) lasted for two years.