我已经尝试了stackoverflow上提到的大多数建议但尚未遇到解决方案。我正在提出的错误如下。
An error occurred at line: 379 in the jsp file: /application-new-project_process.jsp
Lambda expressions are allowed only at source level 1.8 or above
我正在使用 IntelliJ IDEA 2016.2 并已应用这些设置。
Project Structure
→Project
,Project SDK
至1.8 (java version "1.8.0_102")
Project Structure
→Project
,Project Language Level
至8.0 - Lambdas, type annotations etc.
Settings
→Build, Execution, Deployment
→Compiler
→Java Compiler
,Project bytecode version
至1.8
Settings
→Build, Execution, Deployment
→Compiler
→Java Compiler
,Target bytecode version
至1.8
我正在使用 Tomcat v8.0.36 ,并为JSP servlet提供以下内容。
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>compiler</param-name>
<param-value>modern</param-value>
</init-param>
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.8</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.8</param-value>
</init-param>
<init-param>
<param-name>suppressSmap</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
任何建议都将不胜感激!
答案 0 :(得分:13)
我使用IntelliJ IDEA 2016.3.2,tomcat apache-tomcat-8.5.8,以下更改对我来说已经足够了:
1.更改以下文件:apache-tomcat-8.5.8 \ conf \ web.xml
2.修改
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
添加以下init参数:
&LT; INIT-PARAM&GT;
&LT; PARAM-名称&gt;&compilerSourceVM LT; / PARAM-名称&gt;
&LT; PARAM值&GT; 1.8&LT; / PARAM值&GT;
&LT; / INIT-PARAM&GT;
&LT; INIT-PARAM&GT;
&LT; PARAM-名称&gt;&compilerTargetVM LT; / PARAM-名称&gt;
&LT; PARAM值&GT; 1.8&LT; / PARAM值&GT;
&LT; / INIT-PARAM&GT;
完成。
答案 1 :(得分:4)
使用Spring Boot 1.5.9.RELEASE和Tomcat 8.5.23的更新答案。由于Spring Boot / MVC中没有针对Tomcat的XML配置文件,因此我调整了从these spring docs链接的代码,以在我的基础Application类中创建自定义程序bean。修复了在IntelliJ和Gradle CLI中使用JSP中的Java 8语法导致的问题。
@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(MyApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return (ConfigurableEmbeddedServletContainer container) -> {
TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
JspServlet servlet = tomcat.getJspServlet();
Map<String, String> jspServletInitParams = servlet.getInitParameters();
jspServletInitParams.put("compilerSourceVM", "1.8");
jspServletInitParams.put("compilerTargetVM", "1.8");
servlet.setInitParameters(jspServletInitParams);
};
}
}