Donald Trump and John McCain's war of words over military service McCain's spokeswoman denied that his most recent remarks were a swipe at Trump.

 -- President Donald Trump and Arizona Sen. John McCain have had a publicly tense relationship for years now, but some of the most searing exchanges have come over military service.

Trump fired first with a controversial comment during his presidential campaign mocking McCain's years of imprisonment by the North Vietnamese during the Vietnam War. Now a recent comment by McCain was interpreted by many as a swipe at Trump's deferments from serving in that war. McCain's spokesperson has denied that the senator was referring to Trump.

The two men's history with the military could hardly be more different.

McCain, 81, comes from a military family and became a naval aviator. He was shot down during a bombing mission over Hanoi during the Vietnam War and spent five and a half years as a prisoner of war. He earned numerous awards for his service, including two Purple Heart medals and a Silver Star.

Trump, now 71, spent five years at the private New York Military Academy as a teen, which he has described as formative.

According to The New York Times, Trump told a biographer he had "more training militarily than a lot of the guys that go into the military" through his time at the school.

Trump received four student deferments from serving in the Vietnam War. Then, after he graduated from college in 1968, he received a medical deferment for a diagnosis of bone spurs in his heels, according to a New York Times report from August 2016.

In 2015, then-candidate Trump told ABC News chief global affairs correspondent Martha Raddatz that during the war he "had a minor medical deferment for feet, for a bone spur of the foot, which was minor."

At one point during the Vietnam War, he was given a high draft number — 356 out of 366, making it very unlikely he would be called into service — and he told his biographer that even though his number "was so incredible," he felt connected to those who served, the Times reported.

"So I never had to do that," he said of serving. "But I felt that I was in the military in the true sense because I dealt with those people," Trump said in a biography by Michael D'Antonio, according to the Times.

In spite of his assertion of feeling he had been in the military, Trump has openly criticized some who served — among the most prominent being McCain.

"He's not a war hero," Trump said of McCain at the 2015 Family Leadership Summit in Iowa. "He's a war hero because he was captured. I like people who weren't captured."

Though that was certainly one of the most open swipes that Trump has taken at McCain, it wasn't the first time he expressed that sentiment.

In January 2000, when McCain was a candidate for president, Trump told NBC News in an interview, "You would say that maybe he wasn't an actual war hero. He was captured, but maybe not a war hero."

Trump changed his tune on McCain, calling him an "American hero," when it was announced earlier this year that the senator would be returning to Washington, D.C., shortly after being diagnosed with a brain tumor, to cast crucial votes on GOP health care legislation. Trump was later disappointed when McCain voted against legislation supported by the White House, dooming the bill's chances.

For his part, McCain has often openly criticized Trump's policy stances but has steered away from commenting on his lack of military service.

Many people, however, interpreted a recent comment McCain made about draft deferments as a reference to Trump, although his spokesperson has denied the senator was referring to the president.

In a C-SPAN interview for a Vietnam War documentary that aired Sunday, McCain said it was "wrong" that "we drafted the lowest income level of America and the highest income level found a doctor that would say they had a bone spur. That is wrong. That is wrong. If we're going to ask every American to serve, every American should serve."

McCain spokesperson Julie Tarallo told ABC News this morning that he was not talking about Trump but criticizing the Selective Service program during the Vietnam War.

"Sen. McCain was referring to one of the great injustices of the Vietnam conflict that led to a majority of poor, undereducated and minority draftees," Tarallo told ABC in a statement. "Sen. McCain has long criticized the Selective Service program during the Vietnam War, which left the fighting to the less privileged."

ABC News' Mariam Khan and Veronica Stracqualursi contributed to this report.