img
In Listing 21-2, there are two profile values for the SpringBlog application. The first one controls the
service layer implementation to use (jpa or mybatis), and the second (in bold) controls the datasource
bean to initialize. To use MySQL, change the second profile value from h2 to mysql. When the project is
rebuilt and deployed to tc Server, the application will run against the MySQL database.
Switching Between the JPA and MyBatis Implementations
As shown in the previous section, for the service layer, changing from an JPA 2 implementation to an
MyBatis implementation is easy too. You just need to change the first profile value from jpa to mybatis.
For example, for the parameter with the name spring.profiles.active, the value mybatis,mysql
indicates to Spring to load the beans from the respective profiles, which will use the MyBatis
implementation of the service layer and the dataSource bean for MySQL.
As mentioned in Chapter 5, one other method to set the active profile is using the launch
configuration of tc Server. This will eliminate the need of modifying the web.xml file and repackaging the
web application archive file.
To change the launch configuration, in STS's Servers view, double-click the tc Server that the
SpringBlog application is running on, and click the link "Open launch configuration," as shown in Figure
21-5.
Figure 21-5. Setting the launch configuration for tc Server
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home