A single force acting on a free object does not change its shape. It makes the object accelerate instead. To stretch, bend or compress an object, at least two forces must act on it, and they must act in different directions.
To stretch a spring, the forces pull in opposite directions, away from each other. To compress it, the forces push in opposite directions, towards each other. To bend a bar, the forces act in different directions at different points, for example one at each end pushing one way and one in the middle pushing the other way.
If a spring hangs from a clamp, it is the clamp that supplies the second force. A 2 N weight pulls the spring down, and the clamp pulls the top of the spring up. The spring is not accelerating, so the two forces are equal and opposite, so the support pulls up with a force equal to the weight.