Bear spray is pretty effective, if you hit the bear in the face full force.
The local Fish and Game Tech that responds to bear complaint incidents has told me that he, personally, has no use for bear spray. He also teaches bear defense courses. He includes a section on the use of bear spray, but has no use for it himself. He's 100% Brenneke slugs in his Remington 870.
A number of Alaskans carry bear spray for bear protection. In the research I've read on it, bear spray can be pretty darn effective - if deployed properly.
I don't buy it or use it. A co-worker of mine brought a can of bear spray in to work to demonstrate its use to some others in our office that occasionally need to venture out into the wilds. He pointed the bear spray down wind, careful to ensure others wouldn't be affected, squeezed the trigger and... AND... absolutely nothing happened! The can did not spray a **** thing. Talk about an eye opener! He contacted the manufacturer and the manufacturer asked him to check the expiration date. He did and the expiration date was exceeded.
I shared this incident with the local F&G technician and he said he uses instructional cans of bear spray while teaching his courses on bear defense. These demonstration cans are intended to spray identically to the real cans of bear spray but they contain no pepper, and are designed for use in the classroom settings. He told me experienced a failure to fire with a demo can that was within its expiration date. Said he wasn't overly surprised to learn of our experience with the dud can of bear spray.
So ask yourself, how many cartridges have you had fail to fire in your lifetime? What's the expiration date on cartridge, compared to the expiration date on a can of bear spray? And which do you prefer to entrust you health and life to, in an impending bear attack.
I can load 4-7 slugs in the magazine of my 870. IF I should get a misfire, I can eject that dud round and have another round in the chamber in very short order.
How many cans of bear spray do you want to carry with you? How long does it take to get a second can ready to fire if the first can fails to fire. I'm thumbs down on bear spray, but I'm very accomplished with firearms, after 50 years of hunting and shooting experiences.
For the gun shy, or gun inexperienced, bear spray may indeed be the better option. But might I advise you pay attention to the expiration dates, and carry a spare can. Store them in a proper temperature-controlled environment. Do all this, and if both cans fail to fire, I'd conclude God was calling me off this planet, albeit in a fairly painful manner.
EDIT/ADDITION: With respect to bear attacks, experience level with firearms, and any assurance of surviving a full blown bear attack: I purchased a Win Mod 70 Featherweight in 7mm Mauser from a local man ~ 20-25 years ago. Very friendly likeable man. Very experienced with rifles. Guns, shooting, reloading, and hunting were his hobbies. He provided me with his reloading data for that rifle and some of the targets/groups he'd fired. The local gunsmith (my brother) later told me he knew the man well, as he was a good customer. Said the man was an avid shooter. I took the barreled action out of the stock and saw that he'd carefully glass-bedded the rifle, and also lightened the magazine by swiss-cheesing it with a drill press. Guy told me he loved the 280 and 7mm caliber cartridges. This story has an tragic ending. He went for a Sunday spring hike down a local horse trail into the Kenai National Wildlife Refuge maybe 15 years ago. Took a camp stove and some food with him to prepare a mid-day lunch. Was sorta black bear hunting, but mostly out to get some exercise and enjoy the outdoors on a nice, warm, sunny spring day. He took along a .280 caliber rifle, but never returned. Folks went out and found him dead next to a fallen tree trunk. His camp stove, food, and backpack were set up on/against the tree trunk, and all appearances were that he'd stopped for a lunch break. His rifle was found nearby. One empty casing was found on the ground, and one empty casing was still in the chamber. Huge brown bear tracks visible on the ground. I talked to one of the search party, who was a friend of the deceased. He said the top of the man's skull was missing and the brains were exposed. He used not one single adjective I can repeat on this forum to describe this bear. All he had for this bear was utter contempt. The bear was never found, and there was not certain evidence that either fired round hit the bear. One theory was that he may have fired off a warning shot in the effort to scare the bear into backing down, and then perhaps never had time for another well-aimed shot. By all accounts, it was an immense, mature boar. This incident has served to remind me of the harsh reality that no matter the firearm experience of the bear attack victim, sometimes the bear wins. Survival isn't assured or certain no matter the skill and preparation level.