During his commencement address at the U.S. Naval Academy, the president urged Congress to pass a budget that would fund the military and “middle class priorities.” (The Washington Post)

President Obama on Friday used the issue of sexual assault in the military to illustrate to Naval Academy graduates the importance of trust and honor at a time when the public has grown weary of missteps by public servants.

“It only takes the misconduct of a few to further erode people’s trust in their government,” Obama told the graduates at Navy-Marine Corps Memorial Stadium.

“Those who commit sexual assault,” he said, raising an old issue that has drawn renewed public attention in recent days, “are not only committing a crime, they threaten the trust and discipline that makes our military strong.”

A recent Pentagon survey estimated that 26,000 military service members experienced “unwanted sexual contact” last year, although only 3,374 filed sexual-assault reports.

“Our military remains the most trusted institution in America,” Obama said, urging graduates to help maintain that image.

President Barack Obama congratulates Alexis Marisa Werner with open arms during the United States Naval Academy commencment ceremony in Annapolis on Friday. (Pablo Martinez Monsivais/Associated Press)

Obama’s 22-minute address to the academy’s Class of 2013, under a gray, drizzly sky, was his second commencement speech in Annapolis since taking office.

Every spring, the president has spoken at the graduation of one of the service academies, as well as other colleges or universities. He addressed the Naval Academy in 2009, West Point in 2010, the Coast Guard Academy in 2011 and the Air Force Academy in 2012.

The first president to address a Naval Academy commencement was James A. Garfield in 1881. Many others have followed.

Obama appears to relish this ritual as commander in chief.

On Friday, he recalled his first speech to Annapolis graduates in May 2009 in a stadium ringed with names of places that resonate in Navy and Marine history: Pearl Harbor, Coral Sea, Midway, Guadalcanal and many more.

“You were a little younger, and I was too,” he said. “You had your entire Naval Academy experience ahead of you. I was already getting chest bumps from the graduates of 2009.”

Since then, he said, the security landscape has evolved.

“Just as you’ve changed over the past four years, so too have the challenges facing our military,” Obama said. The war in Iraq ended, he said, Navy commandos killed al-Qaeda leader Osama bin Laden, and the United States set a course to wind down its war in Afghanistan.

“Today we salute all the Americans who have made the ultimate sacrifice in these wars, including 18 graduates of this academy,” Obama said. “We honor them all, now and forever.”

Obama also has addressed graduates of Ohio State University and Morehouse College this spring. He was criticized by some African American supporters for focusing too much in his Morehouse address on admonishing the black community for shortcomings.

At Ohio State, the president reassured graduates that their future was bright in an improving economy, and he implored them to use their talents to make the country a better place.

On Friday in Annapolis, there were 1,047 graduates, with 764 receiving commissions as Navy ensigns and 264 as Marine second lieutenants. A handful of others were bound for the Air Force, were graduating without commissions or were foreign officers.

Of the graduates, 841 were men and 206 women.

The president struck a bantering tone in part of his speech, noting that it was an occasion of celebration and forgiveness.

“And so, in keeping with tradition,” he said, “I declare all midshipmen on restriction for minor conduct offenses are hereby absolved. As always, Admiral Miller [the academy’s superintendent, Vice Adm. Michael H. Miller] gets to decide what’s minor.”

He added: “Some of these guys are laughing a little nervously about that.”

After Obama’s speech, the graduates were called one by one from their seats on the stadium turf to receive personal congratulations onstage from the commander in chief. Names were read from each of the 30 companies that form the academy’s brigade. Most shook Obama’s hand. Some hugged him.

Ensign Nathan Swan, 22, of Madera Ranchos, Calif., who is aiming for a submarine assignment, said afterward that he was very impressed. “It was an honor and a privilege to hear him,” Swan said.

His mother, Rene Swan, who put a class ring on the new officer’s finger, said the president’s message about honor resonated with the crowd. “That’s their responsibility, to hold their peers to the highest of standards,” she said.

Before the ceremony, not quite officers yet, the “firsties,” as the fourth-year students are known at the academy, milled about in dress uniforms in a staging area. Rebecca Watson, 22, of Glenn Dale, near Bowie, was about to graduate with a degree in chemistry. She said she was fulfilling a dream that began in fourth grade when she saw a flyover at a football game at the stadium.

“I saw a Navy jet and said, ‘I want to do that,’ ” Watson said. Now she’s headed to flight school in Pensacola, Fla.