And if the Federation went to war yet again, would Starfleet continue to explore, or would they cease that secondary activity and engage in warfare?
Captain's log, stardate 51474.2. The Defiant has been ordered to investigate a rare subspace compression phenomenon recently discovered in Federation space. This scientific assignment is a welcome change from months of combat duty against the Dominion.
And this for a vessel that wasn't even designed to be used for scientific studies. So in answer to your question: Yes, Starfleet would continue to explore.
In fact:
Captain's log, stardate 44429.6. We are on a mapping survey near the Cardassian sector. It has been nearly a year since a peace treaty ended the long conflict between the Federation and Cardassia.
Guess what the Enterprise-D -- the most powerful ship in the entire Starfleet -- was actually doing during this "long conflict"?
Put another way, if Starfleet isn't the Federation's navy/military ... who is?
They don't have one. Starfleet is good enough in that role that they don't NEED one.
In fact, there are a NUMBER of civilizations in the Trekiverse that manage to get by without an actual military. The civilization on Eminar VII is the most famous example: while they are in a constant state of war, they actually abolished their military centuries ago and have done without one ever since. The Organians, also, have nothing that resembles a military or a regular fighting force. The Borg don't even have a CONCEPT of military -- or politics, for that matter -- and just kinda of do what they do whenever they decide to do it. Species 8472 have no "military" to speak of and the entire group of them function like a swarm of locusts, not unlike the Borg.
The Ocampa have no military at all, and no real weapons and no means to defend themselves other than "hide from the bad guys and hope they go away." The Kazon have no military mainly because they have no real government and they're really just a race of heavily armed space hillbillies. The Vidians have no military, just a whole army of high tech repo men. The hirogen have no military, just a fucking enormous gun club.
The Ferengi have no military, just a shitload of guns they don't really know how to use.
The Talarians ARE a military; they have no civilians.
The Klingon word for "military" is derived from an ancient word that roughly means "people whose heads are still attached to their bodies."
22nd century Vulcan, which is amazingly militaristic even by Star Trek standards, doesn't have anything they'd be willing to call a military.
Look at how many active duty military pilots have been assigned to testing space craft, and space exploration.
NASA is not a military organization.