我试图运行使用web应用程序hibernate3.0与struts2-core-2.1.6上Tomcat7.0.55同JDK8.我到了 org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.poste.struts2.bean.CityDetails.我hibernate.cfg.xml是:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/mydb</property>
<property name="connection.username">uname</property>
<property name="connection.password">pass</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping class="com.poste.struts2.bean.CityDetails" />
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
类代码是:
package com.poste.struts2.bean;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name = "city_master")
public …Run Code Online (Sandbox Code Playgroud) 我有一个模板 JSP 页面:
<html>
<head></head>
<body>
<c:set var="temp" scope="request" value="" />
<tile:insertAttribute name="header"/>
<tile:insertAttribute name="body"/>
<tile:insertAttribute name="footer"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的模板 XML 如下:
<tiles-definitions>
<definition name="home" extends="template">
<put-attribute name="temp" value="home" />
<put-attribute name="body" value="/WEB-INF/pages/home.jsp" />
</definition>
<definition name="template" template="/WEB-INF/templates/template.jsp">
<put-attribute name="temp" />
<put-attribute name="header" value="/WEB-INF/pages/includes/header.jsp" />
<put-attribute name="body" />
<put-attribute name="footer" value="/WEB-INF/pages/includes/footer.jsp" />
</definition>
<tiles-definitions>
Run Code Online (Sandbox Code Playgroud)
我的问题:
当我在 home 定义"home"中的"temp"name 中设置了值时,我想"home"在页眉页和页脚页中获取此值,所以我这样做了,${temp}但我还没有找到"home"值。
这是可能的?如果是,那么如何?
我正在尝试org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping在我的 spring mvc 控制器中自动装配以获取所有 url 映射并将它们显示在 UI 上,但没有成功。有错误,bean 丢失:
org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping web.controller.WorkController.handlerMapping; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Run Code Online (Sandbox Code Playgroud)
我的 web.xml:
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
我的 mvc-dispatcher-servlet.xml:
<context:annotation-config/>
<context:component-scan …Run Code Online (Sandbox Code Playgroud) 我知道如何使用 -Xss 为 java 线程设置堆栈大小,我们在我们的产品中使用它。
但是当我们的应用程序中使用了很多线程并且设置了 -Xss 时(我们设置为 512k 供我们使用)。我们会遇到错误报告无法创建新的本地线程。它应该与堆栈大小有关,因为当我们设置 -Xss256k 时,错误消失了。
我的问题是对于 1 个线程,Xss 设置堆栈大小,但是对于所有线程堆栈大小呢?
整个线程的总堆栈内存大小的限制是什么?我没有找到这样的 JVM 设置,而我们现在似乎遇到了这样的问题。
intelliJ中的Ctrl+ Shift+ A命令让我搜索一个动作.Eclipse中是否有等效的命令?
您好,在尝试使用 Spring Boot 发送 SMTP 电子邮件时,我在遵循教程后不断收到此错误。 Failed messages: javax.mail.MessagingException: can't determine local email address
application.properties:#email configuration
spring.mail.host = smtp.gmail.com
spring.mail.password = ************
spring.mail.username = ******@gmail.com
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.ssl.enable = true
spring.mail.properties.mail.smtp.socketFactory.port = 465
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback = false
Run Code Online (Sandbox Code Playgroud)
@Service("mailServiceImpl")
public class MailServiceImpl {
@Autowired
private JavaMailSender javaMailSender;
public void send(String to, String subject, String body) throws MessagingException {
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
mimeMessageHelper.setSubject(subject);
mimeMessageHelper.setTo(to);
mimeMessageHelper.setText(body, true);
javaMailSender.send(mimeMessage);
}
} …Run Code Online (Sandbox Code Playgroud) 我正在编写一个无阻塞的Spring Rest控制器.我的客户端应该发送请求,不关心响应,也不需要等待.
这是我的服务器代码:
@RestController
@EnableAsync
public class testController {
@RequestMapping(value = "test", method = RequestMethod.GET)
public ResponseEntity<String> test() throws InterruptedException {
timeConsumingMethod();
System.out.println("I'm should be first");
return new ResponseEntity<String>("the server is processing your request", HttpStatus.OK);
}
@Async
private void timeConsumingMethod() throws InterruptedException {
Thread.sleep(1000*5);
System.out.println("I'm should be second!");
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用(POSTMAN,Chrome等)调用http:// localhost:8181/test时,我在服务器日志中得到以下信息:
我应该是第二名!
我应该是第一个
并且等待5秒后我的浏览器显示:
服务器正在处理您的请求
这是"发送和忘记"行为的正确方法吗?
我收到错误java.lang.IndexOutOfBoundsException:Index:0,Size:0.
public Collection<AdDistribution> getAdDistribution(byte srch, byte cont) throws IndexOutOfBoundsException {
List<AdDistribution> mediums = new ArrayList<>();
List<AdDistribution> adDistribution = new ArrayList<>();
adDistribution.add(AdDistribution.SEARCH);
adDistribution.add(AdDistribution.CONTENT);
if (adDistribution.isEmpty()) {
return null;
}
if (srch == 0 && cont == 0) {
mediums = new ArrayList<>();
mediums.set(0, adDistribution.get(0));
}
if (srch == 1 || cont == 1) {
mediums = new ArrayList<>();
if (srch == 1) {
mediums.set(0, adDistribution.get(0));
} else if (cont == 1) {
mediums.set(0, adDistribution.get(1));
}
}
if (srch == 1 && …Run Code Online (Sandbox Code Playgroud) 我的 Java 项目中有 2 个分支:master 和 refactor。我已经完成了重构的工作,所以现在想checkout master将重构合并到 master 中。在进行重构时,我还向 .gitignore 添加了一些文件(其中一个是 .idea),现在我得到:
[michal@michal-pc MCleaner]$ git checkout master
error: The following untracked working tree files would be overwritten by checkout:
.idea/description.html
.idea/misc.xml
.idea/modules.xml
.idea/project-template.xml
.idea/vcs.xml
Please move or remove them before you switch branches.
Aborting
Run Code Online (Sandbox Code Playgroud)
我已经阅读了很多帖子,但没有任何效果。如何在不访问 master 分支的情况下删除这些文件?有没有办法解决这个问题?如果可以,请提供 cmd 命令,我还是 git 新手。
这是来自的输出git status:
On branch refactor
Your branch is up-to-date with 'origin/refactor'.
Untracked files: (use "git add <file>..." to include in what will be committed) …Run Code Online (Sandbox Code Playgroud) 我正在使用Struts2框架和Hibernate,我正在增强一个我没有启动的系统,我增强了系统的一些功能并在产品上实现了它。但是,当他们使用登录模块中的Acunetix进行扫描时,系统中检测到一些威胁(警报),其中警报显示:
警报:SQL 注入
严重性:高
描述:该脚本可能容易受到 SQL 注入攻击。
建议:您的脚本应该过滤用户输入中的元字符。查看详细信息以获取有关修复此漏洞的更多信息。
然后,我检查了该警报中出现错误的脚本。老开发人员使用 Hibernate 创建查询。
List<UserBean> users = session.createQuery("from UserBean where username =?")
.setParameter(0,username)
.list();
Run Code Online (Sandbox Code Playgroud)
我的问题是:
- 使用 Hibernate 的此查询是否无法避免 SQL 注入?
-.setParameter是否应该.setString更具体以避免 SQL 注入?
或者以上都不是?
谢谢你的时间。
java ×7
hibernate ×2
spring-mvc ×2
apache-tiles ×1
asynchronous ×1
eclipse ×1
email ×1
git ×1
git-checkout ×1
git-merge ×1
intellij-12 ×1
java-8 ×1
jsp ×1
jstl ×1
mime-message ×1
rest ×1
spring ×1
spring-boot ×1
stack ×1
tiles ×1
tomcat ×1