I have one Spring project but it has two build configurations:
- WAR build to be run on a Tomcat container
- Standalone executable JAR
So I have separate context/servlet XMLs for each of them to tell how I want to initialise the beans.
- With the WAR build, I have something like this for my
@Autowiredannotations<context:component-scan base-package="com.package.my"/> - With the standalone executable JAR, I have this instead
<context:annotation-config/>
So here is the problem. I want to add a new class that extends the PrintStream class. Like this:
package com.package.my;
import java.io.PrintStream;
...
@Component
public class MyPrintStream extends PrintStream { ... }
However, I want to initialize MyPrintStream differently for WAR build and JAR build.
- For WAR build, I want to initialize it in this fashion (if doing it without
@Autowired):MyPrintStream myPrintStream = new PrintStream(new java.io.ByteArrayOutputStream(), true, java.nio.charset.StandardCharsets.UTF_8.name()); - For JAR build, I just want to do it like this (if doing it without
@Autowired):MyPrintStream myPrintStream = System.out;
If I have to do these on context/servlet XML for @Autowired, how can I initialize the object differently?
Note: Not sure if I am thinking this in the right way. Please correct me if I am wrong. Other opinions are also welcome.