Use Maven to manage projects and maven to manage projects

Source: Internet
Author: User

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());    }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.