It is possible to 'overwrite' a java class, via including it in the classpath - load ordering depends on the server being used. For Tomcat, the load order is:
- Bootstrap classes of your JVM
- System class loader classes
- /WEB-INF/classes of your web application
- /WEB-INF/lib/*.jar of your web application
- Common class loader classes
Search around a bit and make sure you're attempting this in the right manner; it's going to vary per server, as I said earlier - and I imagine there are some that it's not possible.
I'm not sure I would recommend this as an approach - although there are plenty of StackOverflow comments and blogs that do similar things. I'm sure it's plausible, but our resources were not able to make this work and moved on to a different method.
The only way I've personally seen this done successfully, is to remove the bean declaration of RestResponseFactory from the RestConfiguration, and establish it elsewhere - which still requires modifying the RestResponseFactory directly. I would recommend this, which is basically an endorsement of the clone+edit method.
Hope this helps,