小编Plo*_*log的帖子

不推荐使用WebMvcConfigurerAdapter类型

我只是迁移到spring mvc版本5.0.1.RELEASE但突然在eclipse中STS WebMvcConfigurerAdapter被标记为已弃用

public class MvcConfig extends WebMvcConfigurerAdapter {
  @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
        // to serve static .html pages...
        registry.addResourceHandler("/static/**").addResourceLocations("/resources/static/");
    }
  ....
  }
Run Code Online (Sandbox Code Playgroud)

我怎么能删除这个!

java spring spring-mvc

102
推荐指数
2
解决办法
8万
查看次数

在Angular 2中的模板中键入cast

我正在研究一个Angular项目(Angular 4.0.0),我无法将抽象类的属性绑定到ngModel,因为我首先需要将它作为实际的具体类来转换为访问该属性.

即我有一个AbstractEvent类,它有一个具体的实现Event,它有一个布尔属性'acknowigned',我需要通过ngModel双向绑定来设置一个复选框.

我目前在我的DOM中有这个元素:

<input type="checkbox" *ngIf="event.end" [(ngModel)]="(event as Event).acknowledged" 
                                          [disabled]="(event as Event).acknowledged">
Run Code Online (Sandbox Code Playgroud)

不幸的是,这会引发以下错误:

未捕获错误:模板解析错误:分析器错误:缺少预期)在第8列[(事件为事件).已确认]

谷歌搜索似乎表明这可能是因为在模板中使用它时不支持使用'as'?虽然我不确定这一点.

我也无法弄清楚如何在驱动模板的typescript文件中为它编写一个函数,因为这会破坏我需要的ngModel上的双向绑定.

如果有人有办法解决这个问题或正确地在角度模板中进行类型转换,我将非常感激!

typescript angular

22
推荐指数
7
解决办法
8319
查看次数

Kotlin编译器返回:未解析的参考:Spring 5.0中的springframework

我正在尝试使用Kotlin和Spring 5.0一起使用但是我遇到了Kotlin编译器没有识别出对Spring的任何引用的问题:

[错误]无法执行目标org.jetbrains.kotlin:kotlin-maven-plugin:1.1.1:在项目kotlin-mvc-project上编译(编译):编译失败:编译失败:

[错误](文件位置):[7,12]未解决的参考:springframework

我正在使用Spring里程碑版Spring 5.0.0.M5和Kotlin版本1.1.1(在我的kotlin-compiler和IntelliJ Kotlin插件上).IDE在我的任何Kotlin文件中都没有突出显示编译错误,但运行kotlin-compiler似乎根本看不到Spring 5.0.

有没有人有任何想法如何解决这个问题?我正在使用Maven进行这个项目,我附上了我的POM以供参考:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>kotlin-mvc-project</groupId>
<artifactId>kotlin-mvc-project</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <kotlin.version>1.1.1</kotlin.version>
    <spring.version>5.0.0.M5</spring.version>
</properties>

<repositories>
<repository>
    <id>spring-milestones</id>
    <name>Spring Milestones</name>
    <url>https://repo.spring.io/libs-milestone</url>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
</repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
    </dependency>

    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-compiler</artifactId>
        <version>${kotlin.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

</dependencies>

<build>
    <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
    <plugins>
        <plugin>
            <artifactId>kotlin-maven-plugin</artifactId>
            <groupId>org.jetbrains.kotlin</groupId>
            <version>${kotlin.version}</version>

            <executions>
                <execution>
                    <id>compile</id> …
Run Code Online (Sandbox Code Playgroud)

spring maven kotlin

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

使用 Python3 将 meld 设置为 git mergetool

我试过将 meld 设置为我的合并工具以与 git 一起使用:

git config --global merge.tool meld
git config --global mergetool.meld.path c:/Progra~2/meld/bin/meld
Run Code Online (Sandbox Code Playgroud)

如对以下问题的回答所述:

如何将 Meld 设置为 git mergetool

我曾经在我的旧工作机器上运行过这个,但现在在我安装了 Python3 而不是 2.7 的新机器上,每当我尝试 git mergetool 时,我都会收到以下错误:

C:/Program Files/Git/mingw64/libexec/git-core/mergetools/meld: c:/Progra~2/Meld/bin/meld: C:/msys64/MINGW32/bin/python3.exe: 错误解释器: 否这样的文件或目录

任何想法我需要采取哪些额外步骤才能使其与 Python3 一起使用?

编辑:我也尝试过直接指向 Meld.exe 但这会导致以下崩溃:

在此处输入图片说明

python git meld git-merge python-3.x

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

C++:析构函数在它应该超出范围之前被调用?

我遇到的问题是在子程序结束时为析类调用析构函数,即使它应该在子程序范围之外定义.

这是我所拥有的最小的代码,它显示了我的问题:

#include <iostream>
using namespace std;

class Foo {
private:

    double *array;

public:

Foo(int N) {
   array = new double[N];
   for (int i=0; i<N; i++) {
       array[i]=0;
   }
}

~Foo() {
   delete[] array;
}
};

void subroutine(Foo x) {
   cout << "Hello!" << endl;
}

int main() {
   Foo bar(10);
   subroutine(bar);
   subroutine(bar);
}
Run Code Online (Sandbox Code Playgroud)

现在,对象栏的析构函数在第一个子例程完成后被调用,即使它的范围应该是整个main()函数?这意味着当我调用第二个子例程时,再次调用析构函数并且我得到内存泄漏.

我发现我可以通过在子程序中通过引用调用来解决这个问题,但我对这个修复不太满意,因为我不明白为什么它首先不起作用.任何人都可以为我阐明这一点吗?

谢谢.

c++ destructor

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

如何在Mockito测试中修复RestTemplate.exchange的空值响应?

我的服务类如下,其后是测试 -

@Service
public class MyServiceImpl implements MyService {

        @Autowired
        private RestTemplate restTemplate;

        @Override
        public StudentInfo getStudentInfo(String name) {
            HttpHeaders headers = new HttpHeaders();
            headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);

            HttpEntity entity = new HttpEntity(headers);

            StudentInfo student = null;

            URI uri = new URI("http:\\someurl.com");             

           ResponseEntity<String> responseEntity = restTemplate.exchange(uri,
                        HttpMethod.GET, entity,
                        String.class);

           if (responseEntity.getStatusCode().equals(HttpStatus.NO_CONTENT)) {
                   throw new Exception("Student absent");
            }else {
              ObjectMapper mapper = new ObjectMapper();
              StudentInfo student = mapper.readValue(responseEntity.getBody(), StudentInfo.class);

           }

            return student;
        }
    }
Run Code Online (Sandbox Code Playgroud)

测试类:在我下面的测试类中,我看到ResponseEntity对象在调试时为null,导致NPE.

@RunWith(MockitoJUnitRunner.class)
public class MyServiceImplTest {

    @InjectMocks
    private MyService …
Run Code Online (Sandbox Code Playgroud)

junit spring-test mockito spring-boot spring-boot-test

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