You are thinking about him in the back of your mind, so he is appearing in your dreams.
Mostly people dream because they happen to be thinking about that person. But when you are asleep and falling asleep, your train of thoughts go out of order, so that's probably the reason.
You may be dreaming about your ex-boyfriend as a way to process the feelings which you have regarding him. The feelings that you have in the dream, however, may not always represent the feelings you feel in everyday life...
A dream can sometimes be our minds way of "dealing" with our emotions and often anxieties. For example, if you dream about your ex crying, then it may suggest that you feel guilty, or are worried about him on some level. It may also be indicative of unfinished business.Dreaming of an ex-boyfriend may also represent feelings of loss, or simply a craving for a relationship, although not necessarily with him. Perhaps the most obvious meaning is that there may still be feelings remaining for your ex.
Even if you are happy with the choices that have been made, some feelings which we may not register in our day to day life can come to the surface in dreams.
However, a dream does not always represent our feelings about certain people. The people we see in our dreams may in fact represent someone or something else, and they can contain all kinds of metaphors, so try not to get too hung up on what you dreamt about.
If he is your ex-boyfriend, this suggests something didn't work out in your relationship. I would recommend not dwelling upon it, as being stuck in the past is painful and unproductive.