Spring Boot Integration Test - Maven Tests missing JSTL -
i trying implement integration test using selenium our application. idea load applicationcontext of our springmvc project, start embedded tomcat container , run integration tests on it, before shutting down , finalizing applications compilation.
now running junit test out of eclipse starts server spring boot perfectly, when running maven tests , accessing website (through selenium or not), following exception:
org.apache.jasper.jasperexception: absolute uri: http://java.sun.com/jsp/jstl/core cannot resolved in either web.xml or jar files deployed application
however, jstl on classpath scope test
in maven. know, why happening?
my configuration split on parent project, internal library used in our projects , 1 actual project. omitted uninteresting parts of pom.xml:
<properties> <apache.tiles.version>3.0.4</apache.tiles.version> <tomcat.version>7.0.59</tomcat.version> </properties> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-jsp</artifactid> <version>${apache.tiles.version}</version> </dependency> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-core</artifactid> <version>${apache.tiles.version}</version> </dependency> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-api</artifactid> <version>${apache.tiles.version}</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet.jsp</groupid> <artifactid>jsp-api</artifactid> <version>2.2</version> <scope>provided</scope> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-module-junit4</artifactid> <version>${powermock.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-api-mockito</artifactid> <version>${powermock.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>com.google.code.gson</groupid> <artifactid>gson</artifactid> <version>2.3.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.hsqldb</groupid> <artifactid>hsqldb</artifactid> <version>2.2.8</version> <scope>test</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> <scope>runtime</scope> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <version>${spring.boot.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>2.47.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-core</artifactid> <version>${tomcat.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-el</artifactid> <version>${tomcat.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-logging-juli</artifactid> <version>${tomcat.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-websocket</artifactid> <version>${tomcat.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-jasper</artifactid> <version>${tomcat.version}</version> <scope>test</scope> </dependency>
testconfig.java:
@enableautoconfiguration @springbootapplication @import({ gvappconfiguration.class, secsecurityconfig.class, testmvcconfig.class }) @importresource({ "classpath:applicationcontext.xml", "classpath:/meta-inf/applicationcontext-commons.xml", "classpath:/applicationcontext-solr.xml" }) public class testconfig extends springbootservletinitializer { @override protected springapplicationbuilder configure(final springapplicationbuilder application) { return application.sources(testconfig.class); } public static void main(final string[] args) { springapplication.run(testconfig.class); } }
indexcontrollertest.java:
@runwith(springjunit4classrunner.class) @springapplicationconfiguration(classes = testconfig.class) @webintegrationtest(value = "server.port=9000") @seleniumtest(driver = firefoxdriver.class, baseurl = "http://localhost:9000") public class indexcontrollertest { @autowired private webdriver webdriver; @test public void testcontroller() { webdriver.gettitle(); } }
it turns out default maven's surefire plugin employs trick wherein creates manifest-only jar file, in order avoid need pass full classpath forked jre (see article). jetty jsp processor asks each classloader list of urls, , sees 1 manifest-only jar file, rather jar files being used, , hence doesn't find tld files.
the simple solution, documented on page, turn off usemanifestonlyjar option, follows:
<plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-surefire-plugin</artifactid> <version>2.18.1</version> <configuration> <usemanifestonlyjar>false</usemanifestonlyjar> </configuration> </plugin> .... <plugin>
this instructs surefire directly pass full classpath forked jre process, thereby allowing locate tlds. answer taken from here.
Comments
Post a Comment