我是 maven 的新手。我正在使用 apache-maven-3.2.2 来构建我的项目。它的简单项目将从客户端接收 json 数据,在服务器端它将将此 json 数据转换为其类似的 java 类。用于转换将 json 格式转换为 java 格式,我们使用的是 google 的 Gson 库。没有 maven,我的项目运行正常。但是当我将其转换为 maven 时,出现以下错误:
Caused by: java.lang.NoClassDefFoundError: com/google/gson/Gson
at com.edfx.tsn.web.controller.DataController.transferData(DataController.java:51) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_17]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_17]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_17]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_17]
at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.13.Final.jar:]
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
... 22 more
Run Code Online (Sandbox Code Playgroud)
从错误中很明显它无法 Gson jar。
现在下面是我的 pom.xml 文件
<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>TestJSON</groupId>
<artifactId>TestJSON</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TestJSON</name>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source> …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用 Spring JdbcTemplate 类。我有以下代码:
List<PersonDTO> personList = jdbcTemplate.query(query, new RowMapper<PersonDTO>() {
@Override
public PersonDTO mapRow(ResultSet rs, int rowNumber) throws SQLException {
PersonDTO personDTO = new PersonDTO ();
personDTO.setPerId(rs.getString("COL_ONE"));
personDTO.setIdTypeCd(rs.getString("COL_TWO"));
return personDTO;
}
});
Run Code Online (Sandbox Code Playgroud)
现在我想RowMapper用 java8 lamda 表达式替换匿名类,如下所示:
Runnable r1 = () -> {
System.out.println("My Runnable");
};
Run Code Online (Sandbox Code Playgroud)
是否可以???
我的项目中有一个场景,我需要开发一个异步服务,该服务将从 Spring Boot 执行一些数据库更新操作。我知道@Async总是会生成一个新线程。因此,我正在采取以下操作:
我创建了两个单独的服务类。
第一服务等级[例如服务等级 A]
@Async
@Override
public Future<MyResponseModel> myMethodForApproval(parameterList) {
MyResponseModel myResponseModel= new MyResponseModel();
serviceClassB.performApproval(parameterList);
myResponseModel.setStatus("Success");
myResponseModel.setMessage("Approval process initiated successfully");
return new AsyncResult<MyResponseModel>(myResponseModel);
}
Run Code Online (Sandbox Code Playgroud)
在第二个服务类中【说服务类B,写的是实际的业务逻辑】
@Transactional(readOnly = false, propagation = REQUIRES_NEW, rollbackFor = { Throwable.class })
public void performApproval(parameterList) {
//all the business logic checking.
repoLayer.saveAll(myEntities);
Run Code Online (Sandbox Code Playgroud)
}
在控制器层:
@RequestMapping(value = "/approveProcess", method = RequestMethod.POST, consumes = { "application/json" })
public ResponseEntity<MyResponseModel> approveProcess(@RequestBody parameterList) {
serviceClassA.myMethodForApproval(parameterList);
}
Run Code Online (Sandbox Code Playgroud)
现在我得到了例外
org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; …Run Code Online (Sandbox Code Playgroud) 我在 windows 和 unix 系统中部署了一个 java 代码。我必须添加文件权限才能将文件移动到特定目录(在 unix 中)。我为此使用PosixFilePermission 。
file1 = new File( expFilePath+ "/" + creationDate);
file1.mkdir();
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_WRITE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.GROUP_EXECUTE);
try {
Files.setPosixFilePermissions(file1.toPath(), perms);
} catch (IOException e1) {
e1.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在unix中运行正确,但在windows m/c中导致UnsupportedOperationException,我必须在windows m/c中运行代码时手动注释这段代码。
有什么方法可以检测java中的底层操作系统类型并有条件地执行这段代码吗?
I am building a Spring-boot application where I am using Spring data jpa feature.
Please find below my dao layer code
package com.adv.dao;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface CustomerDao extends JpaRepository<Customer, String> {
}
Run Code Online (Sandbox Code Playgroud)
I am using a DaoProvider class as follows:
package com.adv.dao;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository
public class DaoProvider implements Serializable {
private static final long serialVersionUID = 1L;
@Autowired
private CustomerDao customerDao;
public CustomerDao getCustomerDao() {
return customerDao;
}
}
Run Code Online (Sandbox Code Playgroud)
My spring …
我是Thymeleaf的新手,我有一个Spring-Boot应用程序,该应用程序在视图页面中使用了Thymeleaf组件。
<form action="#" th:action="@{/saveStudent}" th:object="${user}" method="post">
<table>
<tr>
<td>Enter Your name</td>
<td><input type="text" th:field="*{userName}"/></td>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
上面的代码对我来说很好用。
现在,在使用eclipse代码辅助时,我遇到了几个百里香标签/属性th:form,th:formaction。
一旦我将上面的代码更改为以下格式:
<th:form th:formaction="@{/saveStudent}" th:object="${user}" method="post">
<table>
<tr>
<td>Enter Your name</td>
<td><input type="text" th:field="*{userName}"/></td>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</th:form>
Run Code Online (Sandbox Code Playgroud)
它停止工作。我的网页没有提交到服务器。因此,我想了解以下内容:
th:form标签的用途是什么?th:action和th:formaction标签之间有什么区别?