使用maven练习spring ioc练习时,
在test文件夹中编写测试类代码用main方法失败
代码如下图所示–
public static void main(String[] args) {
UserService userService = new UserServiceImpl();
userService.getUser();
}
}
方法一:
将其改为以下代码即可
public class myTest {
@Test
public void test(){
UserService userService = new UserServiceImpl();
userService.getUser();
//默认获取用户的数据
}
}
方法二
重新看一下原先用main方法的报错信息为
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:exec (default-cli) on project 01-spring-ioc: Command execution failed.
找到maven中的本地仓库,然后依据\org\codehaus\mojo\mojo-parent找到mojo文件夹,将其删除
D:\ maven中的本地仓库\org\codehaus\mojo\mojo-parent
删除mojo文件后,在idea项目中找到pom.xml ,配置如下代码
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<classpathScope>test</classpathScope>
<!--<mainClass></mainClass>-->
</configuration>
</plugin>
</plugins>
</build>
如果此时导入插件的版本号等信息标红,不用管它,直接去运行test目录下的main方法,maven会自己下载插件