Good question. I'm interested to see if anyone has a good answer, I don't.
It only takes a little anxiety to kill the boner and stressing about it makes it worse. For me it has meant getting comfortable with people first, being in a safe and sane encounter, and then repeating encounters. It is not conducive to hookups. I think it is based on one's personnality or psyche if you will, which is a combination of genetic predisposition and developmental factors.
I know some people try to medicate (CBD, or THC, viagra, etc), which i guess if you can find the right combination may work. I've dabbled down that route, using a little cialis or viagra as a crutch to help get over the hump. The therapy route is a long term expensive project.