With my children I have always let them know it hurts me; that seems to have nipped it in the bud as they are very empethetic, but it does take a few times since at that age they tend to be more reactive. Just be consistent with your response until he eventually catches on.
First: remind yourself it’s developmentally normal Second: these tips really helped me! https://www.rootandriseblog.com/7-useful-hacks-for-dealing-with-toddlers-hitting-phase-gentle-respectful-parenting-techniques/