Bayern sporting director Hasan Salihamidzic said in a statement on Sunday: "We wish Lucas a full and speedy recovery. Our doctors are very pleased with the course of the operation. He will be available again in a few weeks."
Hernandez has made 62 appearances for Bayern in all competitions since joining from Atletico Madrid two years ago.
The 25-year-old has suffered only one defeat in his 42 Bundesliga games, while he did not lose a single one of the 25 league matches he played in his first season at the Allianz Arena as Bayern won the treble under Hansi Flick.
The German champions, now coached by Julian Nagelsmann, begin their title defence away to Borussia Monchengladbach on August 13.