Use Maven to manage projects and maven to manage projects
Recently, the trainer project uses Maven to manage projects. When Maven is used to manage projects, modules are developed at Layer-3 development. parent-dao-service-web, all the dependencies of spring + struts + Hibernate are added to the parent, and dao-service-web is used as sub-modules. Several problems occur when dealing with the relationship between modules:
I didn't add the dependency of Junit in the parent project. In the dao module, I added the jar package of Junit. Of course, I wrote the test range in scope, however, the Junit test in the service module shows that the Junit package is not dependent on. Why? Baidu figured it out. It turned out to be the jar package after the dao module installed on the service. When the dao module was installed, the Junit package with scope as test was certainly not released, in the service, the dependency on the Junit package cannot be passed. This solution can only add the dependency of the Junit package to the service.
Because modular development is adopted, spring configuration files are distributed in various modules. When you need to read the spring configuration files from multiple modules during the test project, A previously unused annotation is used:
@ ContextConfiguration (locations = {"classpath *: applicationContext -*. xml "}) * wildcard in this annotation indicates that the configuration file starting with applicationContext-in the class path of this module and the dependent jar package will be loaded (only the spring configuration file will be named like this)
//@ContextConfiguration(locations={"classpath*:applicationContext-*.xml"})@ContextConfiguration(locations={"classpath:applicationContext-dao.xml","classpath:applicationContext-service.xml"})@RunWith(SpringJUnit4ClassRunner.class)public class CustomerServiceImplTest { @Autowired private CustomerService customerService; @Test public void test() { Customer customer = customerService.findById(1L); System.out.println("********************"+customer.getCustName()); }}