The Talmud (Berachot 8A) seems to indicate that Shimi Ben Geira was King Shlomo's teacher:
ואמר רבי חייא בר אמי משמיה דעולא לעולם ידור אדם במקום רבו שכל זמן ששמעי בן גרא קיים לא נשא שלמה את בת פרעה
R. Hiyya b. Ammi further said in the name of 'Ulla: A man should always live in the same town as his teacher. For as long as Shimei the son of Gera was alive Solomon did not marry the daughter of Pharaoh.
However, there doesn't seem to be any indication in Nach that Shimi ben Geira was King Shlomo's teacher.
In Melachim 2:8-9, David tells Shlomo to find a way to kill Shimi ben Geira for cursing David, since David swore he would not kill Shimi ben Geira.
In Melachim 2:36-44, we see how Shlomo puts Shimi ben Geira under house arrest, waits for him to violate it, and then kills him.
There is no mention of him being Shlomo's teacher.
How do we know that Shimi ben Geira was Shlomo's teacher? Is the source this Gemara, or is there some other source?