You can place a dispenser then hook up a redstone clock to it then it shoots until it runs out of arrows or you break the redstone connection to the dispenser.
Try hooking it up with an AND gate between dispenser and clock. Hook up the other AND input to a switch wherever you want, and flip it whenever you see stuff in the target area. Then you won't even need to knock out redstone to turn it off. And it won't freak out and waste a ton of arrows for a few minutes after killing a target. Less waste = less maintenance.
For even better defense, the dispenser(s) could also be hooked up (directly or connected via OR gate to the switch line) to pressure plates in the target area that also link to an alarm system that alerts you to intruders while you're not standing watch. It will then fire on the intruder when the pressure plate gets pressed, every time it's pressed, until you get to the switch and turn it to killmode.
If it's used like this in a narrow hallway, you can also use a wooden pressure plate in front and put a stack of cobble/planks/sticks into it so it will occasionally spit out an item that will hold the pressure plate down and keep it firing. In which case you may be better off simply hooking it up to the clock directly. XD
Private Mod Note
Rollback Post to RevisionRollBack
Minecraft is a game about placing blocks to build anything you can imagine. (Source)
Anything built within Minecraft, using only Minecraft, without using bugs, is legit.
If you don't want to build mob traps, that's fine. Just don't tell us it's cheating.
a basic system would involve using something like a 3-clock or a stable 1-clock to make them repeat once the initial trigger is applied. Advancing on this design, one could establish an AND gate and link one side to the clock, the other side to a lever or a pressure plate, allowing for controlled dispensing. a pressure plate could be used for traps, levers for base defenses. I think i saw a really nifty design that involved hiding a dispenser behind a painting, after destroying the painting the dispenser would shoot the would-be griefer or the extremely curious.