It is also because of the poem of Tang Dynasty poet Wang Wei: "When those red berries come in spring, they bloom in your southern branches. Take them home for me as a symbol of our love." By love with red beans.
This poem is widely praised, so it has formed idioms similar to allusions.
Added is:
There is another legend. According to legend, there was a young woman in ancient times who died in frontier fortress because she missed her husband. She leaned against the tree in front of the door, crying day and night, and her tears dried up. Blood flowed out of her eyes, and blood and tears dyed her roots red, thus producing red beans with acacia significance. It's called locust bean.