在我当前的spring项目中,当我运行应用程序并使用以下代码打开视图时:
<form:select path="${entry.key}" class="form-control">
<c:forEach var="option" items="${values[entry.key]}">
<form:option value="${option.id}" label="${option.nome}" class="form-control"/>
</c:forEach>
</form:select>
或
<c:forEach var="option" items="${values[entry.key]}">
<form:checkbox path="${entry.key}" value="${option.id}" label="${option.nome}" class="form-control"/>
</c:forEach>
我收到错误:
java.lang.ClassNotFoundException: org.springframework.core.enums.LabeledEnum
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.springframework.web.servlet.tags.form.AbstractCheckedElementTag.isOptionSelected(AbstractCheckedElementTag.java:61)
at org.springframework.web.servlet.tags.form.AbstractCheckedElementTag.renderFromValue(AbstractCheckedElementTag.java:51)
at org.springframework.web.servlet.tags.form.AbstractCheckedElementTag.renderFromValue(AbstractCheckedElementTag.java:40)
at org.springframework.web.servlet.tags.form.CheckboxTag.writeTagDetails(CheckboxTag.java:90)
at org.springframework.web.servlet.tags.form.AbstractSingleCheckedElementTag.writeTagContent(AbstractSingleCheckedElementTag.java:87)
at org.springframework.web.servlet.tags.form.CheckboxTag.writeTagContent(CheckboxTag.java:53)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:103)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.jsp.private_.cadastrar_jsp._jspx_meth_form_005fcheckbox_005f0(cadastrar_jsp.java:936)
at org.apache.jsp.WEB_002dINF.jsp.private_.cadastrar_jsp._jspx_meth_c_005fforEach_005f3(cadastrar_jsp.java:895)
at org.apache.jsp.WEB_002dINF.jsp.private_.cadastrar_jsp._jspx_meth_c_005fwhen_005f4(cadastrar_jsp.java:857)
at org.apache.jsp.WEB_002dINF.jsp.private_.cadastrar_jsp._jspService(cadastrar_jsp.java:304)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
与我需要添加到项目中的可能库有关。我的pom.xml
是这样的:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.5.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
任何人都可以告诉我应该向依赖项中添加哪些库以允许我解决此错误?
更新
在sugestions之后,我向我的pom.xml添加了依赖spring-core。首先,我添加版本4.0.6,这不解决我的问题。如果我尝试添加版本3.2.9,由于版本与我的应用程序中添加的其他库的冲突,我甚至无法构建应用程序。
因为这个,我现在正在寻找一个解决方案,使用标签form:select
(以及导致相同错误的form:checkbox
)与我正在使用的弹簧版本。下面是一些与此问题相关的代码:
values
的方法。Pagina.java
@Entity
@Table(name="pagina")
public class Pagina {
@Id
@Column(name = "id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@Column(name = "nome", unique=true)
@Order(value=1)
private String nome;
@Column(name = "titulo")
@Order(value=2)
private String titulo;
@Column(name="resumo", length=140)
@Order(value=3)
private String resumo;
@Column(name = "descricao", length=65535)
@Order(value=4)
private String descricao;
@OneToOne( fetch = FetchType.EAGER )
@Order(value=5)
@JoinColumn(name="parent_page")
private Pagina pagina;
@OneToOne( fetch = FetchType.EAGER )
@JoinColumn(name="parent_product")
@Order(value=6)
private Produto produto;
}
cadastra.jsp
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<title>Cadastrar Pagina</title>
</head>
<body>
<form id="command" class="form" action="/loja/Pagina/cadastra" method="POST" enctype="multipart/form-data">
<div class="panel panel-default">
<div class="panel-heading"></div>
<div class="panel-body">
<div class="row">
<div class="col-md-4">
<label for="titulo">titulo</label>
</div>
<div class="col-md-8">
<input id="titulo" name="titulo" class="form-control" type="text" value=""/>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="resumo">resumo</label>
</div>
<div class="col-md-8">
<input id="resumo" name="resumo" class="form-control" type="text" value=""/>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="nome">nome</label>
</div>
<div class="col-md-8">
<input id="nome" name="nome" class="form-control" type="text" value=""/>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="descricao">descricao</label>
</div>
<div class="col-md-8">
<textarea id="descricao" name="descricao" class="form-control"></textarea>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">produto</div>
<div class="panel-body">
<select id="produto" name="produto" class="form-control">
</select>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">pagina</div>
<div class="panel-body">
<select id="pagina" name="pagina" class="form-control">
</select>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">imagem da capa (jpeg, 1280x250)</div>
<div class="panel-body">
<input type="file" name="picture" class="form-control">
</div>
</div>
<p>
<button type="submit" class="btn btn-lg btn-primary">cadastrar</button>
</p>
<div id="yes" class="alert alert-success" role="alert" style="display: none;">
<strong>Pagina</strong> cadastro efetuado com sucesso!
</div>
<div id="image" class="alert alert-warning" role="alert" style="display: none;">
<strong>Pagina</strong> cadastro efetuado com sucesso, mas nenhuma imagem foi salva.
</div>
<div id="icone" class="alert alert-warning" role="alert" style="display: none;">
<strong>Pagina</strong> cadastro efetuado com sucesso, mas nenhum ícone foi salvo.
</div>
<div id="all" class="alert alert-warning" role="alert" style="display: none;">
<strong>Pagina</strong> cadastro efetuado com sucesso, mas nenhuma imagem ou ícone foram salvos.
</div>
<div id="not" class="alert alert-danger" role="alert" style="display: none;">
<strong>Pagina</strong> n*atilde;o foi possivel efetuar o cadastro.
</div>
</form>
<script>
$(document).ready(function(){
$('form.form').ajaxForm(function(data) {
$("#"+data).css("display", "block");
$('form.form').each(function(){
this.reset();
});
$("#"+data).fadeOut(5000);
});
$("input[name='senha']").on("change", function() {
var senha = $(this).val();
var senha_md5 = hex_md5(senha);
$("input[name='senha']").val(senha_md5);
});
});
</script>
</body>
</html>
getListaAtributos()
public Map<String, List<String>> getListaAtributos() {
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> lista = this.getAtributos();
for(int i=0; i<lista.size(); i++)
{
Class<?> clazz;
try {
String class_name = "com.spring.loja.model."+lista.get(i).toLowerCase()+".persistence.model."+capitalize(lista.get(i));
clazz = Class.forName(class_name);
} catch (ClassNotFoundException e) {
clazz = null;
}
if(clazz != null) {
Field[] campo = clazz.getDeclaredFields();
int max = campo.length;
List<String> temp = new ArrayList<String>();
for(int j=0; j<max; j++)
temp.add(campo[j].getName());
map.put(lista.get(i), temp);
} else {
map.put(lista.get(i), null);
}
}
return map;
}
任何人都可以看到这里有什么问题?
答案 0 :(得分:3)
观看您的传递依赖关系。通过使用问题和mvn dependency:tree
中的信息,这就是我得到的:
+- org.springframework:spring-context:jar:4.0.3.RELEASE:compile
| +- org.springframework:spring-aop:jar:4.0.3.RELEASE:compile
| +- org.springframework:spring-beans:jar:4.0.3.RELEASE:compile
| +- org.springframework:spring-core:jar:4.0.3.RELEASE:compile
| \- org.springframework:spring-expression:jar:4.0.3.RELEASE:compile
+- org.springframework.security:spring-security-web:jar:3.2.3.RELEASE:compile
| +- aopalliance:aopalliance:jar:1.0:compile
| +- org.springframework.security:spring-security-core:jar:3.2.3.RELEASE:compile
| \- org.springframework:spring-web:jar:3.2.8.RELEASE:compile
+- org.springframework.security:spring-security-config:jar:3.2.3.RELEASE:compile
+- org.springframework.security:spring-security-taglibs:jar:3.2.3.RELEASE:compile
| \- org.springframework.security:spring-security-acl:jar:3.2.3.RELEASE:compile
+- org.springframework.ws:spring-ws-core:jar:2.1.4.RELEASE:compile
| +- org.springframework.ws:spring-xml:jar:2.1.4.RELEASE:compile
| +- org.springframework:spring-oxm:jar:3.2.4.RELEASE:compile
| +- org.springframework:spring-webmvc:jar:3.2.4.RELEASE:compile
| +- wsdl4j:wsdl4j:jar:1.6.1:compile
| +- javax.xml.stream:stax-api:jar:1.0-2:compile
| \- commons-logging:commons-logging:jar:1.1.1:compile
+- org.springframework:spring-orm:jar:4.0.3.RELEASE:compile
| \- org.springframework:spring-jdbc:jar:4.0.3.RELEASE:compile
\- org.springframework:spring-tx:jar:4.0.3.RELEASE:compile
您可以看到旧版本的 Spring WS 和 Spring Security 也提取了一些旧的 Spring Framework 依赖项。我强烈建议将<dependencyManagement>
部分添加到您的POM中并强制这些依赖项为4.0.3:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web/artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>