How do you maintain java webapps in different staging environments?

后端 未结 13 2539
傲寒
傲寒 2020-12-29 10:23

You might have a set of properties that is used on the developer machine, which varies from developer to developer, another set for a staging environment, and yet another fo

相关标签:
13条回答
  • 2020-12-29 10:45

    Don't forget to investigate PropertyPlaceholderConfigurer - this is especially useful in environments where JNDI is not available

    0 讨论(0)
  • 2020-12-29 10:47

    I recently also used Maven for alternative configurations for live or staging environments. Production configuration using Maven Profiles. Hope it helps.

    0 讨论(0)
  • 2020-12-29 10:50

    I just use different Spring XML configuration files for each machine, and make sure that all the bits of configuration data that vary between machines is referenced by beans that load from those Spring configuration files.

    For example, I have a webapp that connects to a Java RMI interface of another app. My app gets the address of this other app's RMI interface via a bean that's configured in the Spring XML config file. Both my app and the other app have dev, test, and production instances, so I have three configuration files for my app -- one that corresponds to the configuration appropriate for the production instance, one for the test instance, and one for the dev instance.

    Then, the only thing that I need to keep straight is which configuration file gets deployed to which machine. So far, I haven't had any problems with the strategy of creating Ant tasks that handle copying the correct configuration file into place before generating my WAR file; thus, in the above example, I have three Ant tasks, one that generates the production WAR, one that generates the dev WAR, and one that generates the test WAR. All three tasks handle copying the right config file into the right place, and then call the same next step, which is compiling the app and creating the WAR.

    Hope this makes some sense...

    0 讨论(0)
  • 2020-12-29 10:56

    We use different ant targets for different environments. The way we do it may be a bit inelegant but it works. We will just tell certain ant targets to filter out different resource files (which is how you could exclude certain beans from being loaded), load different database properties, and load different seed data into the database. We don't really have an ant 'expert' running around but we're able to run our builds with different configurations from a single command.

    0 讨论(0)
  • 2020-12-29 10:56

    Caleb P and JeeBee probably have your fastest solution. Plus you don't have to setup different services or point to files on different machines. You can specify your environment either by using a ${user.name} variable or by specifying the profile in a -D argument for Ant or Maven.

    Additionally in this setup, you can have a generic properties file, and overriding properties files for the specific environments. Both Ant and Maven support these capabilities.

    0 讨论(0)
  • 2020-12-29 10:58

    We use properties files specific to the environments and have the ant build select the correct set when building the jars/wars.

    Environment specific things can also be handled through the directory service (JNDI), depending on your app server. We use tomcat and our DataSource is defined in Tomcat's read only JNDI implementation. Spring makes the lookup very easy.

    We also use the ant strategy for building different sites (differeing content, security roles, etc) from the same source project as well.

    There is one thing that causes us a little trouble with this build strategy, and that is that often files and directories don't exist until the build is run, so it can make it difficult to write true integration tests (using the same spring set up as when deployed) that are runnable from within the IDE. You also miss out on some of the IDE's ability to check for the existence of files, etc.

    0 讨论(0)
提交回复
热议问题