Four people were injured when shots were fired near a courthouse in western Germany, police said.