Spring Boot - 无法编译jsp

时间:2016-03-10 22:58:23

标签: java spring jsp spring-mvc spring-boot

我正在尝试创建一个Spring Boot Web应用程序,但我无法查看.jsp页面。一切似乎都很好,但当我尝试访问第一页(index.jsp)时,我收到以下错误消息。有任何想法吗?

TIA

org.apache.jasper.JasperException: Unable to compile class for JSP
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:661) ~[tomcat-jasper-7.0.47.jar:7.0.47]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) ~[tomcat-jasper-7.0.47.jar:7.0.47]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) ~[tomcat-jasper-7.0.47.jar:7.0.47]

Caused by: java.lang.ClassCastException: org.apache.el.ExpressionFactoryImpl cannot be cast to javax.el.ExpressionFactory
at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:198) ~[tomcat-embed-el-8.0.32.jar:8.0.32]
at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:117) ~[tomcat-embed-el-8.0.32.jar:8.0.32]

这是我的pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>mil.navy.ecClient</groupId>
  <artifactId>ec-client</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>ec-client</name>

  <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <java.version>1.7</java.version>
      <app.properties>src/main/resources/application.properties</app.properties>
      <!-- List of variables read from application.properties: ${defaultUri} -->
  </properties>

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <dependencies>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
      </dependency>
      <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.16.6</version>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-ws</artifactId>
      </dependency>

      <dependency>
          <groupId>com.h2database</groupId>
          <artifactId>h2</artifactId>
          <scope>runtime</scope>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
          <scope>provided</scope>
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>
      </dependency>
  </dependencies>

  <build>
    <finalName>ec</finalName>

      <plugins>       
        <plugin>
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
            <source>${java.version}</source>
            <target>${java.version}</target>
          </configuration>
          <version>3.5.1</version>
       </plugin>

        <plugin>          
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
              <port>8080</port>
              <path>/ec</path>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
             <execution>
                 <phase>initialize</phase>
                 <goals>
                     <goal>read-project-properties</goal>
                 </goals>
                 <configuration>
                 <files>
                     <file>${app.properties}</file>
                </files>
                </configuration>
            </execution>
          </executions>
         </plugin>
      </plugins>
  </build>
</project>

控制器类:

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class FirstPageController {

   @Autowired
   DataSource dataSource;

   @RequestMapping(value = "/")
   public ModelAndView showFirstPage() {
      System.out.println("first page");
      ModelAndView mav = new ModelAndView("index1");

      return mav;
   }
}

申请类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@EnableAutoConfiguration
@EnableWebMvc
@SpringBootApplication
public class EcClientApplication extends SpringBootServletInitializer {

   private static Class<EcClientApplication> ecApplication = EcClientApplication.class;

   public static void main(String[] args) {
      SpringApplication.run(EcClientApplication.class, args);
   }

   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
      return applicationBuilder.sources(ecApplication);
   }
}

配置类:

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
public class EcClientConfiguration extends WebMvcConfigurerAdapter {

   @Value("${db.path}")
   private String dbPath;

   @Value("${defaultUri}")
   private String defaultUri;

   @Value("${spring.datasource.url}")
   private String dataSourceUrl;


   @Bean
   public DataSource dataSource() {
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName("org.h2.Driver");
      dataSource.setUrl(dataSourceUrl);
      dataSource.setUsername("test");

      return dataSource;
   }

   @Override
   public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
      configurer.enable();
   }

   @Bean
   public InternalResourceViewResolver viewResolver() {
      InternalResourceViewResolver resolver = new InternalResourceViewResolver();
      resolver.setPrefix("WEB-INF/jsps/");
      resolver.setSuffix(".jsp");
      return resolver;
   }

   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
   }

   /**
    * Resolves property values in the properties file with @Value ${} annotation.
    * 
    * @return a new {@link PropertySourcesPlaceholderConfigurer} object for the property.
    */
   @Bean
   public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
      return new PropertySourcesPlaceholderConfigurer();
   }

}

0 个答案:

没有答案
相关问题