作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Groovy 中的 Spring's tutorials 之一编写一些 Spring 代码。 。当我在 Groovy 中编写以下代码时:
@Component
public class SimpleCORSFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
chain.doFilter(req, res);
}
public void init(FilterConfig filterConfig) {}
public void destroy() {}
}
@Component
class SimpleCORSFilter implements Filter {
void doFilter(ServletRequest req, ServletResponse, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse response = res as HttpServletResponse
response.setHeader("Access-Control-Allow-Origin", "*")
chain.doFilter(req, res)
}
void init (FilterConfig filterConfig) {}
void destroy() {}
}
我收到以下错误
Can't have an abstract method in a non-abstract class. The class 'com.myproject.main.SimpleCORSFilter' must be declared abstract or the method 'void doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)' must be implemented.
@ line X, column Y.
@Component
^
我已经实现了抽象的doFilter
方法。为什么无效?
我该如何解决这个问题?
最佳答案
这里有语法错误
void doFilter(ServletRequest req, ServletResponse, FilterChain chain)
应该是
void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
关于java - 如何在 Groovy 中实现抽象 Java 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33048666/
我是一名优秀的程序员,十分优秀!