小编use*_*002的帖子

如何根据URL模式应用spring boot过滤器?

我创建了一个spring boot过滤器 - GenericFilterBean带有@Component注释的实现.

@Component 
public class MyAuthenticationFilter  extends GenericFilterBean {
...
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
...
}
}
Run Code Online (Sandbox Code Playgroud)

该过滤器由Spring Boot Framework自动识别,适用于所有REST API.我希望此过滤器仅应用于某个URL路径,例如/api/secure/*但我找不到正确的方法.我试过@WebFilter但它没用.我没有使用XML配置或servlet初始化程序 - 只是注释.

让它运作的正确方法是什么?

java spring annotations filter spring-boot

16
推荐指数
3
解决办法
2万
查看次数

HTTPListener的Win7服务在一个请求后停止响应

我是新手c#开发者 - 试图写一个简单的win7服务.

该服务应启动HTTPListener并侦听传入的浏览器请求,当收到请求时,它会返回响应并继续侦听其他请求.我不需要处理并行性,因为一次只能有一个请求(非常短).

我使用了以下代码,但在第一次响应后,服务停止响应.我可能需要一个循环,但我不熟悉API,所以我可能也错了我正在做的事情.

谢谢您的帮助.

    protected override void OnStart(string[] args)
    {
        HttpListener listener = new HttpListener();
        listener.Prefixes.Add("http://localhost:9999/");
        listener.Start();

        listener.BeginGetContext(new AsyncCallback(OnRequestReceive), listener);
     }

    private void OnRequestReceive(IAsyncResult result)
    {
        HttpListener listener = (HttpListener)result.AsyncState;
        HttpListenerContext context = listener.EndGetContext(result);
        HttpListenerResponse response = context.Response;
        byte[] buff = {1,2,3};

        response.Close(buff, true);
    } 
Run Code Online (Sandbox Code Playgroud)

c# service http listener windows-7

1
推荐指数
1
解决办法
1778
查看次数

标签 统计

annotations ×1

c# ×1

filter ×1

http ×1

java ×1

listener ×1

service ×1

spring ×1

spring-boot ×1

windows-7 ×1