Liver/gall bladder issues, stress, parasites, intestinal inflammation, and intestinal flora imbalance can play a role in creating gastritis. This can lead to cycles of over- and under-production of hydrochloric acid. This then can cause a vitamin B12 deficiency, which then can lead to autoimmune gastritis.
Intestinal flora imbalance leads to B vitamin deficiencies. B vitamins play a role in the production of hydrochloric caid for the stomach, and the cycle continues.