Most of the time it is not caused by stress, but rather by a specific bacteria. You can get tested for it.
I had esophageal ulcers once from ibuprofen. It was really very bad, I have the photos from the scope. I took a pill that had no coating with very little water, and then I went to sleep. The thing laid in my esophagus and practically burned a hole through it. This could have just as easily had been my stomach. I only take candy coated ibuprofen now, with lots of water and some food.
Stress can be a cause, and stress can certainly exacerbate illness already existing. Stress could cause you to produce more stomach acid, cause your immune system to release cells that harm your tissues, or cause your nervous system to be revved up, but mostly I’m a big believer in finding underlying cause.
As a woman I get pretty annoyed with being told I’m sick because of stress, age, or hormones, when I feel pretty sure there is much more to it. The stress answer to me is typically medicine not knowing what causes it and blaming the patient.