小编chr*_*ke-的帖子

使用Groovy特性编写Geb页面

我有一个自适应网站,并希望从每页主要内容中分离出我的页面模板的某些部分是否已折叠的问题:

trait DesktopPage {
    static content = {
        header { $('nav', id:'nav-container') }
    }
}

trait MobilePage {
    // other stuff
}

trait HomePage {
    static url = ''
    static at = { title == 'My Site' }
}

class DesktopHomePage extends Page implements DesktopPage, HomePage {}
Run Code Online (Sandbox Code Playgroud)

但是,Geb运行时似乎不会从特征中收集static描述块,而是表现为它们不存在.

是否有可能使用Geb特征隐式地构成这样的问题?如果没有,是否有一种语法可以让我从已实现的特征中获取信息?HomePage.at不解决.

groovy multiple-inheritance traits geb

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

为单个Spring Controller指定消息转换器

我正在为一个具有一些奇怪的JSON映射实践的服务编写一个回发处理程序库.我可以非常轻松地配置自定义Jackson ObjectMapper来处理映射,但是如果我使用该映射器注册Spring MVC消息转换器,它会将映射(对于我正在处理的其余JSON不正确)应用于所有传入请求.

我可以应用一些手动方法来手动解码这些消息,但是让Spring类型转换服务在请求管道中处理它会更加清晰.

是否有可行的方法将自定义消息转换器附加到特定控制器,处理程序方法或映射字符串/模板/前缀?

java spring spring-mvc type-conversion

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

当社交登录被代理阻止时,如何通知用户?

我已经在我的应用程序中实现了Facebook登录但是当我在我的办公室中测试我的应用程序Facebook登录无法正常工作,因为Facebook在我的公司被阻止但是当我得到以下异常时看起来很奇怪

The connection was reset

The connection to the server was reset while the page was loading.

    The site could be temporarily unavailable or too busy. Try again in a few moments.
    If you are unable to load any pages, check your computer's network connection.
    If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web. 
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉用户如何告诉用户Facebook在您的网络中阻止,以便更好地登录其他登录类型,如Twitter或Gmail或网站登录.

java twitter jsf spring facebook

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

Spring Boot同步启动器

默认情况下,org.springframework.boot.loader.Launcher将始终在launch()方法中生成后台线程(https://github.com/spring-projects/spring-boot/blob/master/spring-boot-tools/ spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java#L105).有没有简单的方法来改变它在同一个线程中执行,所以我的服务启动器可以知道应用程序何时完全加载,而不是每次都立即退出成功.

java spring spring-boot

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

为什么java.util.function.Consumer没有identity()?

我只是注意到Consumer没有identity()像有那样的方法java.util.function.Function

是的,这只是一个可以放入东西的洞,但至少可以完全清楚地知道我不仅仅是在括号中遗漏了一些代码。

以这个人为的例子为例:

public void applyConsumerIfExists(String key, String param) {
    Map<String, Consumer<String>> consumers = new HashMap<>();
    consumers.put("a", MyClass::myConsumer);

    // I can create my own, but that's no fun :(
    Consumer<String> identity = input -> {};
    consumers.getOrDefault(key, identity).accept(param);

    // DOESN'T WORK, since identity() doesn't exist on Consumer
    consumers.getOrDefault(key, Consumer.identity()).accept(param);
}
Run Code Online (Sandbox Code Playgroud)

问题

为什么没有Consumer方法identity呢?

java java-8

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

Spring bean 已创建,但在 Autowired 时为 null

我正在尝试将一个对象注入一个类。但是,该字段始终为空。我试过@Autowired@Resource注释。我没有在new任何地方使用运算符创建对象。的构造函数Foo被正确调用。

此问题的最小示例:

Foo类

package foo.bar;
public class Foo {
    Foo(){
        System.out.println("Foo constructor");
    }
    public void func() {
        System.out.println("func()");
    }
}
Run Code Online (Sandbox Code Playgroud)

酒吧班

package foo.bar;
public class Bar {
    @Autowired
    private Foo foo;

    public Bar() {
        foo.func();
    }
}
Run Code Online (Sandbox Code Playgroud)

入口点

package foo.bar;
public class HelloApp {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
    }
}
Run Code Online (Sandbox Code Playgroud)

spring-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <context:component-scan base-package="foo.bar"/>
    <bean …
Run Code Online (Sandbox Code Playgroud)

java spring

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

访问此资源需要完全身份验证 - Rest Webservice调用

我的应用程序是使用spring框架开发的.我使用spring框架创建了一个新的rest webservice.

@Controller
public class MyTestController {
   @Inject
    private MyService service;

    @RequestMapping(value = "/acc/Status/{accNum}", method = RequestMethod.GET)
    @ResponseBody
    public String getAccStatus(@PathVariable final String accNum, final HttpServletResponse response) throws Exception
        {
        //logic goes here
        return "success";
  }
Run Code Online (Sandbox Code Playgroud)

为MyService:

public interface BusinessCalendarService {

 //methods..
}
Run Code Online (Sandbox Code Playgroud)

我想看看上面的webservice的响应.我正在使用邮差工具查看回复.当我将请求作为
http:// localhost:8080/myApplication/rest/acc/Status/322298973发出时,它显示以下消息.

HTTP Status 401 - Full authentication is required to access this resource
Run Code Online (Sandbox Code Playgroud)

现有的控制器工作正常,它与我的控制器显示上述消息.请建议我是否需要进行任何代码修改?我按照与编写其他控制器相同的方式进行操作.

java rest spring spring-security

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

为什么 AspectJ 生成空的 Annotation 检查?

我正在使用 AspectJ 1.8.8 编译时编织,并且我有一个像这样的块

@SomeAnnotation(value="someValue")
public List doSomething(String someArg) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

where@SomeAnnotation是通过“Around”建议实现的。

使用 JD-GUI 查看字节码,我看到以下生成的代码(略有格式):

public class SomeClass {
  private static Annotation ajc$anno$5;

  ...

  @SomeAnnotation(value="someValue")
  public List doSomething(String someArg)
  {
    String str = someArg;
    JoinPoint localJoinPoint = Factory.makeJP(ajc$tjp_5, this, this, str);
    Object[] arrayOfObject = new Object[3];
    arrayOfObject[0] = this;
    arrayOfObject[1] = str;
    arrayOfObject[2] = localJoinPoint;
    Annotation tmp56_53 = ajc$anno$5;
    if (tmp56_53 == null) {
      tmp56_53;
    }
    return (List)new SomeClass.AjcClosure11(arrayOfObject).linkClosureAndJoinPoint(69648).around(tmp56_53, (SomeAnnotation)(ajc$anno$5 = SomeClass.class.getDeclaredMethod("doSomething", new Class[] { String.class }).getAnnotation(SomeAnnotation.class))); …
Run Code Online (Sandbox Code Playgroud)

java aop aspectj jd-gui jvm-bytecode

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

在 Firefox 上获取 JSON 时,favicon.ico 被 CSP 阻止

我构建了一个简单的 Spring Boot Rest 控制器,它除了返回自定义 Java 对象 - 数据之外什么也不做。一切都编译并正常运行。当我从端点获取数据时,我得到了预期的数据。

\n

然而,当在 Firefox 上使用“ Inspect Element ”查看底层时,我看到由于内容安全策略 (CSP)导致的错误。内容安全策略错误如下:

\n

错误消息的屏幕截图

\n

“内容安全策略:页面\xe2\x80\x99s 设置阻止加载 http://localhost:8081/favicon.ico (\xe2\x80\x9cdefault-src\xe2\x80\x9d) 上的资源。”

\n

我尝试了几种解决方案,但均无济于事。

\n
    \n
  • 我尝试通过 application.properties 禁用该图标,但这似乎没有任何效果。
  • \n
  • 我创建了一个名为“favicon.ico”的图标并将其放置在正确的目录中。令人烦恼的是,这个页面仍然抛出错误,同时我的所有其他页面都开始获取图标。
  • \n
  • 我尝试了许多标头排列,包括将 Content-Security-Policy 标头设置为默认 src self。没有一个起作用,尽管这可能是问题的根源,因为似乎有很多我没有完全掌握的活动部件。
  • \n
  • 我尝试为“/favicon.ico”创建一个 GET 端点,但这似乎根本没有完成任何事情。\n
      \n
    • 此时我已将图标添加到我的目录中,因此当我尝试访问端点时,它只是向我发送了图标的图像,该图标也显示在浏览器顶部的选项卡中,并且没有错误在日志中。
    • \n
    \n
  • \n
  • 我试图摆弄 WebSecurityConfigurerAdapter,但这很快就失控了,坦率地说,其中很多都没有意义。
  • \n
\n

这是我的文件。

\n

应用程序属性 = application.properties

\n
spring.mvc.favicon.enabled=false\n\n
Run Code Online (Sandbox Code Playgroud)\n

主文件 - DemoApplication

\n
import org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class DemoApplication {\n\n   public static void main(String[] args) {\n …
Run Code Online (Sandbox Code Playgroud)

java firefox spring spring-mvc content-security-policy

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

为什么在Python中打印需要三个撇号?

我在Python 3.3.2中制作了这个毕达哥拉斯定理计算器.

我在几行上打印,以便我可以制作一个图表:

print("Welcome to the Pythagoras Theorem Calculator, powered by Python!")
print("Below are the values a, b and c. You will need to input these values after.")
print('''
      | .
      |   .
      |     .
side a|       . side c
      |         .
      |           .
      |_____________.
          side b
      ''')
Run Code Online (Sandbox Code Playgroud)

如上所示,需要三个撇号而不是语音标记.为什么会这样?这是逃脱角色吗?(我尝试在Google上搜索:http://bit.ly/15a4zes)

python

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