小编krm*_*007的帖子

JVM如何在内部处理竞争条件?

如果多个线程尝试更新相同的成员变量,则称其为竞争条件.但是我更感兴趣的是,如果我们不通过使它同步或其他东西在我们的代码中处理它,JVM如何在内部处理它?它会挂起我的程序吗?JVM将如何应对?我认为JVM会暂时为这种情况创建一个同步块,但我不确定究竟会发生什么.

如果你们中的任何人有一些见解,那么最好知道.

java multithreading jvm race-condition

24
推荐指数
2
解决办法
1667
查看次数

通过Spring启动发送电子邮件"spring-boot-starter-mail"

我正在尝试使用spring boot发送电子邮件,但我得到:

java.lang.UnsupportedOperationException: Method not yet implemented
        at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:89)
        at org.springframework.mail.javamail.SmartMimeMessage.<init>(SmartMimeMessage.java:52)
        at org.springframework.mail.javamail.JavaMailSenderImpl.createMimeMessage(JavaMailSenderImpl.java:325)
Run Code Online (Sandbox Code Playgroud)

我使用过这个maven条目:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.6.RELEASE</version>
    </parent>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.2.6.RELEASE</version>
        </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
        <version>1.2.6.RELEASE</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

application.properties:

spring.mail.host=smtp.gmail.com
spring.mail.port= 25
spring.mail.username= test
spring.mail.password= test
Run Code Online (Sandbox Code Playgroud)

我的代码:

@Autowired
    private JavaMailSender javaMailSender;

private void send() {
        MimeMessage mail = javaMailSender.createMimeMessage();
        try {
            MimeMessageHelper helper = new MimeMessageHelper(mail, true);
            helper.setTo("mymail@mail.co.uk");
            helper.setReplyTo("someone@localhost");
            helper.setFrom("someone@localhost");
            helper.setSubject("Lorem ipsum");
            helper.setText("Lorem ipsum dolor sit amet [...]");
        } catch (MessagingException e) {
            e.printStackTrace();
        } finally {}
        javaMailSender.send(mail);
        //return …
Run Code Online (Sandbox Code Playgroud)

java spring jakarta-mail spring-boot

18
推荐指数
2
解决办法
6万
查看次数

Java中的无限流并行处理

为什么下面的代码不打印任何输出,而如果我们删除并行,它打印0,1?

IntStream.iterate(0, i -> ( i + 1 ) % 2)
         .parallel()
         .distinct()
         .limit(10)
         .forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)

虽然我知道理想的限制应该放在不同之前,但我的问题更多地与添加并行处理引起的差异有关.

java parallel-processing java-8 java-stream

12
推荐指数
2
解决办法
1018
查看次数

Spring TestRestTemplate 与 RestTemplate

RestTemplate和它的测试版有什么区别?当我们通过 进行异常处理时@ControllerAdvice,RestTemplate 抛出异常,但对于相同的流测试版本返回包含异常详细信息的 json。

所以,我想看看它们之间差异的总结。

spring spring-test resttemplate

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

JAXB maven插件不生成类

我试图从XSD生成java文件,但下面的代码不生成.如果我取消注释outputDirectory,它可以工作,但首先删除该文件夹.添加clearOutputDir = false也没有产生任何东西.

<build>
        <plugins>
            <!-- JAXB xjc plugin that invokes the xjc compiler to compile XML schema into Java classes.-->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- The package in which the source files will be generated. -->
                    <packageName>uk.co.infogen.camel.message</packageName>
                    <!-- The schema directory or xsd files. -->
                    <sources>
                        <source>${basedir}/src/main/resources/xsd</source>
                    </sources>
                    <!-- The working directory to create the generated java source files. -->
                    <!--<outputDirectory>${basedir}/src/main/java</outputDirectory>
                    <clearOutputDir>false</clearOutputDir>-->
                </configuration>
            </plugin>
        </plugins>
    </build>
Run Code Online (Sandbox Code Playgroud)

我收到的消息是:

[INFO] --- jaxb2-maven-plugin:2.2:xjc …
Run Code Online (Sandbox Code Playgroud)

java jaxb xjc maven

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

多模块组件扫描在弹簧启动时不起作用

我有两个模块网络和业务.我已将业务纳入网络.但是,当我尝试将业务中的服务接口包含在web中时@autowired,它正在给予org.springframework.beans.factory.NoSuchBeanDefinitionException.

所以,基本上@SpringBootApplication无法扫描@Service来自业务模块.

它是简单的,我想念?

如果我@Bean@SpringBootApplication课堂上添加该服务,它工作正常.

码:

package com.manish;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
public class SpringBootConfiguration {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootConfiguration.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

模块1中的类,从模块2调用类:

package com.manish.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.co.smithnews.pmp.service.contract.UserRegistrationService;

@RestController
@RequestMapping("/testManish")
public class SampleController {

    @Autowired
    private SampleService sampleService;
....
}
Run Code Online (Sandbox Code Playgroud)

第2单元:

package com.manish.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SampleServiceImpl …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

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

静态导入在IntelliJ中的lombok builder中不起作用

我在IntelliJ中使用Lombok.虽然当我尝试对Lombok构建器进行静态导入时,其他一切工作正常,但IntelliJ构建项目找不到构建器类.如果您不使用静态导入,它可以正常工作.

java intellij-idea lombok

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

Kafka Listener的Swagger文档

我使用Swagger为rest API生成一个文档,但我正在构建Kafka监听器并希望为它生成一个文档.我们是否有可能使用Swagger或类似的东西?

谢谢,Manish

spring swagger swagger-ui spring-kafka

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

Kubernetes:kubectl 运行:找不到命令

我正在运行 kubectl 命令以在 gcloud 中部署我的应用程序。但是突然 kubectl 命令停止工作。kubectl命令工作正常,但对于其他所有内容,它说找不到命令。

kubectl create bash: kubectl create: command not found

kubectl run bash: kubectl run: command not found

SBGML02586:~ mku01$ kubectl
kubectl controls the Kubernetes cluster manager. 

Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/

Basic Commands (Beginner):
  create         Create a resource from a file or from stdin.
  expose         Take a replication controller, service, deployment or pod and
expose it as a new Kubernetes Service
  run            Run a particular image on the cluster
  set            Set specific …
Run Code Online (Sandbox Code Playgroud)

gcloud kubernetes kubectl

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

thymeleaf spring boot templates子文件夹中的视图

我在春季靴子里使用百里香,并有几个看法.我不希望将所有视图保留在默认情况下src/main/resources/templates的同一文件夹中.

是否可以在src/main/resources/templates/folder1中移动一些视图,并且我将传递"folder1/viewname "来访问该页面?

当我尝试http:// localhost:8080/folder1/layout1时,它没有在src/main/resources/templates/folder1 /中找到我的html,但当我在模板主文件夹src/main/resources/templates中移动html时/,http:// localhost:8080/layout1工作正常.

我的控制器类看起来像:

@RequestMapping(value = "{pagename}", method = RequestMethod.GET)
public String mf42_layout1(@PathVariable String pagename) {
    return pagename;
}
Run Code Online (Sandbox Code Playgroud)

所以,我想如果我通过layout1,它将看起来模板,如果我说"a/layout1",它将在/ layout文件夹中查找

谢谢,Manish

spring spring-mvc thymeleaf spring-boot

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