小编Rob*_*ram的帖子

Java类文件格式主要版本号列表?

我在另一篇文章中看到了Java的主要版本号列表:

  • Java 1.2使用主要版本46
  • Java 1.3使用主要版本47
  • Java 1.4使用主要版本48
  • Java 5使用主要版本49
  • Java 6使用主要版本50
  • Java 7使用主要版本51
  • Java 8使用主要版本52
  • Java 9使用主要版本53
  • Java 10使用主要版本54
  • Java 11使用主要版本55

参考文献:

https://blogs.oracle.com/darcy/entry/source_target_class_file_version https://en.wikipedia.org/wiki/Java_class_file#General_layout

java version

144
推荐指数
4
解决办法
9万
查看次数

通过注释实现@Autowired @Lazy @Components的最佳方式?

有没有办法通过注释进行仍在工厂中的@Lazy加载?我发现的问题是,通过在工厂中自动装配我的惰性组件,它们将在加载工厂后立即实例化,从而否定惰性注释.@Component@Autowired

我已经定义了几个懒豆,比如

@Component
@Lazy
public final class CloseableChromeWebDriver
      extends ChromeDriver
      implements DisposableBean {
...
}

@Component
@Lazy
public final class CloseableFirefoxWebDriver
      extends FirefoxDriver
      implements DisposableBean {
...
}
Run Code Online (Sandbox Code Playgroud)

重要的是他们懒惰,因为

  • 只要创建其中一个,就会弹出浏览器窗口.
  • 我的数据驱动测试可能需要也可能不需要任何一个或全部,即一次运行可能都是Firefox,或者可能需要Firefox和Chrome.
  • 这更重要,因为事实上我有六个这样的bean - Firefox,Chrome,IE,远程Firefox,远程Chrome,远程IE.
  • 所以,如果我的测试只使用其中一个,那么我只希望显示一个浏览器,而不是所有它们.

我有一个工厂用于获取所请求的浏览器,但我第一次尝试此操作失败,因为无论何时任何类使用工厂,所有自动装配的bean都会立即实例化,无论它们是否实际被请求.我理解这是因为一旦实例化了类,它必须实例化属于它的所有实例变量.

@Component
public final class WebDriverFactory {
   @Autowired
   private CloseableChromeWebDriver chromeWebDriver;
   @Autowired
   private CloseableFirefoxWebDriver firefoxWebDriver;

   public synchronized WebDriver getWebDriver(final Browser browser) {
     // get whatever webdriver is matched by the enum Browser.
   }
}
Run Code Online (Sandbox Code Playgroud)

所以这是我的第二种方法,即通过应用程序上下文请求bean来确保延迟加载:

@Component
public final class WebDriverFactory { …
Run Code Online (Sandbox Code Playgroud)

java spring lazy-loading

30
推荐指数
1
解决办法
3万
查看次数

通过JMockit调用私有方法来测试结果

我使用JMockit 1.1,我想做的就是调用私有方法并测试返回值.但是,我无法从JMockit De-Encapsulation示例中了解如何执行此操作.

我试图测试的方法是这个类中的私有方法:

public class StringToTransaction {
   private List<String> parseTransactionString(final String input) {
      // .. processing
      return resultList;
   }
}
Run Code Online (Sandbox Code Playgroud)

我的测试代码如下.

@Test
public void testParsingForCommas() {
   final StringToTransaction tested = new StringToTransaction();
   final List<String> expected = new ArrayList<String>();
   // Add expected strings list here..
   new Expectations() {
      {
         invoke(tested, "parseTransactionString", "blah blah");
         returns(expected);
      }
   };
}
Run Code Online (Sandbox Code Playgroud)

而我得到的错误是:

java.lang.IllegalStateException:此时缺少对mocked类型的调用; 请确保仅在声明合适的模拟字段或参数后才会出现此类调用

也许我在这里误解了整个API,因为我认为我不想模拟这个类..只是测试调用私有方法的结果.

java junit jmockit private-methods

14
推荐指数
1
解决办法
3万
查看次数

无法实例化TestExecutionListener

当我从Eclipse中运行下面的selenium测试时,我Could not instantiate TestExecutionListener在日志中收到一系列消息.

这是实际测试.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SeleniumConfig.class)
public final class TestWebpage {
   private static final Logger LOG = Logger.getLogger(TestWebpage.class);

   @Autowired
   private WebDriver driver;

   @Test
   public void testLoadingPage() {
      LOG.debug("Hello World!");
   }
}
Run Code Online (Sandbox Code Playgroud)

这是日志

0    [main] INFO  org.springframework.test.context.support.DefaultTestContextBootstrapper  - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
5    [main] INFO  org.springframework.test.context.support.DefaultTestContextBootstrapper  - Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. …
Run Code Online (Sandbox Code Playgroud)

java spring selenium-webdriver

11
推荐指数
4
解决办法
2万
查看次数

Tomcat 7中的SSL

我试图按照在Tomcat 7中为本地应用程序设置SSL的说明进行操作.我真的不明白我在这里做什么,所以请原谅我的方法.我创建了一个密钥库,如下所示:

keytool -genkey -alias tomcat -keyalg RSA
Enter keystore password:  changeit
Re-enter new password: changeit
What is your first and last name?
  [Unknown]:  Robert Bram
What is the name of your organizational unit?
  [Unknown]:  Developers
What is the name of your organization?
  [Unknown]:  MyBusiness
What is the name of your City or Locality?
  [Unknown]:  Melbourne
What is the name of your State or Province?
  [Unknown]:  Victoria
What is the two-letter country code for this unit? …
Run Code Online (Sandbox Code Playgroud)

ssl tomcat7

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

通过maven从测试类运行main方法

我的pom.xml中有以下内容:

<build>
   ...
   <plugins>
   ...
      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>1.2.1</version>
          <configuration>
              <mainClass>com.myorg.MyClass</mainClass>
          </configuration>
      </plugin>
   </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

该类com.myorg.MyClass位于我的测试源目录中,我可以使用以下命令运行它:

mvn -e exec:java -Dexec.classpathScope="test"
Run Code Online (Sandbox Code Playgroud)

我想要:

  1. 避免必须使用-Dexec.classpathScope="test",但我无法弄清楚如何配置该插件在测试类路径中查找.
  2. 为其他类编写更多的插件(每个类都有不同的配置),但是现在我只能运行exec:java.有没有办法标记这个插件,以便我通过该标签调用它,而不是只是说"运行在exec:java中的任何东西"?
  3. 拉入一处-javaagent房产.我在我的pom.xml中定义了这个属性,测试用例正在使用它.我的"自定义"插件会选择这些属性还是我需要做任何事情来吸引他们?

这是属性,直接在其下定义<project>.

<properties>
   <spring.version>3.2.6.RELEASE</spring.version>
   <atomikos.version>3.9.2</atomikos.version>
   <loadTimeWeaverArgLine>-javaagent:"${settings.localRepository}/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar"</loadTimeWeaverArgLine>
</properties>
Run Code Online (Sandbox Code Playgroud)

尝试配置文件

继@ Michal的建议(/sf/answers/2158787711/)之后,这就是我的尝试:

<profile>
   <id>run-importer</id>
   <properties>
      <loadTimeWeaverArgLine>-javaagent:"${settings.localRepository}/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar"</loadTimeWeaverArgLine>
   </properties>
   <build>
      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
               <executable>java</executable>
                  <!--
                     None of these three options work.
                     <commandlineArgs>-javaagent:C:/Users/robbram/.m2/repository/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar</commandlineArgs>
                     <commandlineArgs>${loadTimeWeaverArgLine}</commandlineArgs>
                     <commandlineArgs>-javaagent:"${settings.localRepository}/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar"</commandlineArgs>
                     <argLine>${loadTimeWeaverArgLine}</argLine>
                  -->
               <classpathScope>test</classpathScope>
               <mainClass>com.myorg.MyClass</mainClass>
            </configuration>
         </plugin>
      </plugins>
   </build>
</profile>
Run Code Online (Sandbox Code Playgroud)

我运行它:

mvn -e …
Run Code Online (Sandbox Code Playgroud)

maven-plugin maven

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

bash edit-and-execute-command echo

当我运行以下一行循环时,我得到了预期的输出.

for index in $(seq 1 5) ; do echo "$(date +"%Y%m%d" -d "20160301 $index day")"; done
20160302
20160303
20160304
20160305
20160306
Run Code Online (Sandbox Code Playgroud)

但是当我使用bash的edit-and-execute-command(control- x,control- e)并输入相同的一行循环时,我会得到输出,其中包含意外命令.

for index in $(seq 1 5) ; do echo "$(date +"%Y%m%d" -d "20160301 $index day")"; done
seq 1 5
date +"%Y%m%d" -d "20160301 $index day"
20160302
date +"%Y%m%d" -d "20160301 $index day"
20160303
date +"%Y%m%d" -d "20160301 $index day"
20160304
date +"%Y%m%d" -d "20160301 $index day"
20160305
date +"%Y%m%d" …
Run Code Online (Sandbox Code Playgroud)

bash

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

此外,尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误

我已经用我的.htaccess文件

  1. 提供404页面
  2. 关闭目录扫描。

这是文件的相关部分.htaccess

Options -Indexes
ErrorDocument 404 /Page-Not-Found.html
Run Code Online (Sandbox Code Playgroud)

404 部分有效。测试

但是,转到实际存在的目录(目录扫描)会返回以下内容:

Forbidden
You don't have permission to access /chihuahuaStories/2014/ on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Run Code Online (Sandbox Code Playgroud)

apache .htaccess mod-rewrite

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

我可以在Lucene查询字符串中执行count(*)吗?

我正在使用一个系统,我可以提供Lucene查询字符串,但无法访问Lucene API本身.我只提供一个查询字符串并获取特定于域的结果对象列表.

从我到目前为止的阅读,似乎我不能select count(*) where ...只用查询字符串做相当于一个,但我不是100%肯定我理解.它是否正确?

java lucene elasticsearch

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

在 Bootstrap 4 中显示单选按钮组的无效反馈文本

我正在尝试设置一个 Bootstrap 4 表单,该表单将根据Bootstrap 4 表单页面的自定义样式部分显示错误文本。我逐字使用了他们自己的表单的一部分,然后添加了一个单选组,但是当您尝试提交表单时,不会显示单选组的错误文本(“请选择一个选项。”)。

// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
  'use strict';

  window.addEventListener('load', function() {
    var form = document.getElementById('needs-validation');
    form.addEventListener('submit', function(event) {
      if (form.checkValidity() === false) {
        event.preventDefault();
        event.stopPropagation();
      }
      form.classList.add('was-validated');
    }, false);
  }, false);
})();
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>




<form class="container" id="needs-validation" novalidate>
  <div class="row">
     <div class="custom-controls-stacked d-block my-3">
       <label class="custom-control custom-radio">
         <input …
Run Code Online (Sandbox Code Playgroud)

validation twitter-bootstrap twitter-bootstrap-4

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