ANNAPOLIS, Md. — President Obama used a commencement speech before Naval Academy graduates on Friday to urge them to follow an “inner compass” and to warn that rising numbers of sexual assaults in the military threatened to erode America’s faith in the armed forces.