跑测试没有web环境的情况

有时候 当你跑测试的main方法的时候,会有一些莫名其妙的错误,明明mave pom的包是全的,web跑起来不会报错,可是在main方法下就是报错了,这个时候引入 

  1. <dependency>
  2. <groupId>org.apache.openejb</groupId>
  3. <artifactId>javaee-api</artifactId>
  4. <version>5.0-1</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>javax.faces</groupId>
  8. <artifactId>jsf-api</artifactId>
  9. <version>1.2_04</version>
  10. <scope>test</scope>
  11. </dependency>
  12. <dependency>
  13. <groupId>javax.servlet</groupId>
  14. <artifactId>jstl</artifactId>
  15. <version>1.2</version>
  16. <scope>test</scope>
  17. </dependency>
  18. <dependency>
  19. <groupId>javax.servlet.jsp</groupId>
  20. <artifactId>jsp-api</artifactId>
  21. <version>2.1</version>
  22. <scope>test</scope>
  23. </dependency>
  24. <dependency>
  25. <groupId>javax.faces</groupId>
  26. <artifactId>jsf-impl</artifactId>
  27. <version>1.2_04</version>
  28. <scope>test</scope>
  29. </dependency>

引入上面一串 javaee 依赖 ,在main方法跑测试的时候,99%问题都可以解决,同理单元测试一样,但是不要真的获取javaee 对应的servlet等  会没数据的,上面的引入环境为scope为test,不会影响到正常打包发布
原文地址:https://www.cnblogs.com/signheart/p/6604a19871cc3f29e737777eaf05886c.html