Questions tagged «java»

Java是一种流行的高级编程语言。如果您在使用或理解语言本身时遇到问题,请使用此标签。这个标签很少单独使用,最常与[spring],[spring-boot],[jakarta-ee],[android],[javafx],[gradle]和[maven]结合使用。

9
如何忽略PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException?
尝试将请求发布到http服务器时,出现以下异常: 这是我使用的代码 URL url = new URL( "https://www.abc.com"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setDoOutput(true); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); // wr.writeBytes(params); wr.flush(); wr.close(); BufferedReader br = new BufferedReader(new InputStreamReader( conn.getInputStream())); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } 这是例外: Exception in thread "main" javax.net.ssl.SSLHandshakeException: …

4
在类和方法上定义@Transactional有什么区别
情况1 @Transactional public class UserServiceImpl implements UserService { ................... public void method1(){ try{ method2(); }catch(Exception e){ } } public void method2(){ } } 案例2 public class UserServiceImpl implements UserService { ................... public void method1(){ try{ method2(); }catch(Exception e){ } } @Transactional public void method2(){ } } 在情况1中,如果发生任何异常,则回滚有效,但在情况2中,回滚无效。如果遵循case1,是否有任何性能问题?


8
在Spring Boot中以编程方式配置DataSource
使用Spring Boot,我可以JdbcTemplate使用以下实例化一个: 码: @Autowired private JdbcTemplate jdbcTemplate; 特性: spring.datasource.url=jdbc:postgresql://my_url:my_port/my_other_stuff spring.datasource.username=my_user_name spring.datasource.password=my_password spring.datasource.driver-class-name=org.postgresql.Driver 这将创建一个数据源类: org.apache.tomcat.jdbc.pool.DataSource 如何以编程方式设置DataSource用户名/密码? 我们有一项政策,不要以纯文本格式存储凭据,我必须在工作的地方使用特定的凭据提供程序。

8
使用Spring AOP获取方法参数?
我正在使用Spring AOP并具有以下方面: @Aspect public class LoggingAspect { @Before("execution(* com.mkyong.customer.bo.CustomerBo.addCustomer(..))") public void logBefore(JoinPoint joinPoint) { System.out.println("logBefore() is running!"); System.out.println("hijacked : " + joinPoint.getSignature().getName()); System.out.println("******"); } } 以上方面拦截addCustomer方法执行。addCustomer方法将字符串作为输入。但是我需要在addCustomer方法内部记录传递给方法的输入logBefore。 有可能这样做吗?
74 java  spring 

6
java.util.AbstractList.add上的UnsupportedOperationException
我遇到了使代码块无法正常运行的问题。我不完全确定这段代码的作用(我正在尝试获取一个过时的插件,无法与我们的服务器正常工作),我只知道它每20分钟运行一次并抛出错误。这是发生问题的代码部分: public class DynamicThread extends Thread { private LocalShops plugin = null; public DynamicThread(ThreadGroup tgroup, String tname, LocalShops plugin) { super(tgroup, tname); this.plugin = plugin; } public void run() { Map<ItemInfo, List<Integer>> itemStockMap = Collections.synchronizedMap(new HashMap<ItemInfo, List<Integer>>()); //Dump all the shop stock data into the map. for ( Shop shop …

2
是否检测到BluetoothAdapter的状态更改?
我有一个带有按钮的应用程序,用于打开和关闭BT。我的代码如下: public void buttonFlip(View view) { flipBT(); buttonText(view); } public void buttonText(View view) { Button buttonText = (Button) findViewById(R.id.button1); if (mBluetoothAdapter.isEnabled() || (mBluetoothAdapter.a)) { buttonText.setText(R.string.bluetooth_on); } else { buttonText.setText(R.string.bluetooth_off); } } private void flipBT() { if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable(); } else { mBluetoothAdapter.enable(); } } 我叫按钮Flip,它会翻转BT状态,然后叫ButtonText,它应该更新UI。但是,我遇到的问题是,打开BT需要花费几秒钟的时间-在这几秒钟中,BT状态未启用,即使我的按钮在2秒钟内打开,我的按钮也会关闭蓝牙。 我STATE_CONNECTING在BluetoothAdapter android文档中找到了该常量,但是...我只是不知道如何使用它,无论是新手还是所有人。 因此,我有两个问题: 有没有一种方法可以将UI元素(例如按钮或图像)动态地绑定到BT状态,以便当BT状态更改时,按钮也将更改? …

6
如何在Windows / Linux上设置Java Swing应用程序的DPI?
如果您有一个DPI超过150的显示器(例如Macbook Pro),您可能还会发现问题:Java Swing应用程序上的字体对于高DPI显示器来说太小了,我根本无法更改字体大小(直接忽略Windows DPI,仅显示非常原始的DPI-> 96。除了更改屏幕分辨率外,我无能为力,这绝对会使LCD上的所有内容变得模糊。 是的,我有一台具有高DPI监视器的笔记本电脑,分辨率为1920x1080,分辨率为15.6英寸,某些Java桌面应用在笔记本电脑上看起来很小,例如Matlab,Burpsuite等。我已经在互联网上搜索了很长时间了,但是仍然找不到解决问题的方法。我知道我可以通过更改JRE字体JRE_HOME/lib/font/fontconfig.properties.src,但是找不到任何位置来设置Java桌面字体的默认字体大小或DPI。 问题没有解决办法吗?您有高DPI监视器吗?您如何使用此类应用程序?Swing会放弃DPI高用户吗?
74 java  swing  matlab  fonts  dpi 


5
从Zip文件中的文件读取内容
我正在尝试创建一个简单的Java程序,该程序从zip文件中的文件读取和提取内容。压缩文件包含3个文件(txt,pdf,docx)。我需要阅读所有这些文件的内容,并且为此使用了Apache Tika。 有人可以帮我实现此功能。到目前为止,我已经尝试过了,但是没有成功 程式码片段 public class SampleZipExtract { public static void main(String[] args) { List<String> tempString = new ArrayList<String>(); StringBuffer sbf = new StringBuffer(); File file = new File("C:\\Users\\xxx\\Desktop\\abc.zip"); InputStream input; try { input = new FileInputStream(file); ZipInputStream zip = new ZipInputStream(input); ZipEntry entry = zip.getNextEntry(); BodyContentHandler textHandler = new …

2
使用Lambda的Java 8过滤器数组
我有一个double[],我想在一行中过滤掉负值(不创建新数组)而不添加for循环。使用Java 8 Lambda表达式是否可能? 在python中,将使用生成器: [i for i in x if i > 0] 是否可以在Java 8中做类似的简洁操作?
74 java  lambda  java-8 


10
如何反编译为Java文件intellij的想法
IDEA具有强大的内置功能-反编译器。它可以很好地工作。我可以复制源代码,但是找不到将所有反编译的Java类提取到Java文件的选项。 这个项目有很多Java类和程序包,所以我很想手动复制它。 有谁知道如何提取到Java源文件。谢谢

4
反转Java 8中的比较器
我有一个ArrayList并想按降序对其进行排序。我用它的java.util.stream.Stream.sorted(Comparator)方法。这是根据Java API的描述: 返回由该流的元素组成的流,并根据提供的进行排序Comparator。 这种方法给我一种升序排序。我应该更改哪个参数,以使其具有降序顺序?


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.