我在部署/发布到Glassfish时收到此错误消息。 我正在使用Glassfish 4.0,Eclipse Kepler,Maven,Spring Security和PostGreSQL数据库。
今天早些时候一切正常,我可以毫无错误地发布。然后希望解决一些其他问题,其中jsp-page无法找到ManagedBean类,虽然我之前成功使用过托管bean,但我右键单击了我的项目并且做了#34;构建项目"然后右键单击project-> Maven-> Update Project,我在其他地方读到了。 之后出现错误。
我想类路径有问题,因为我注意到build-folder中缺少一些java-classes,可以在eclipse中的项目资源管理器中看到。 不幸的是,这是我的第一个JavaEE / Maven项目,所以我不知道如何解决这个问题。
来自Stacktrace的相关部分(多次出现):org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [util.MyAuthenticationHandler] for bean with name 'myAuthenticationHandler' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: util.MyAuthenticationHandler
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:385) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:354) [spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:82) [spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609) [spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) [spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:5362) [web-core.jar:na]
at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:743) [web-glue.jar:na]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5898) [web-core.jar:na]
at com.sun.enterprise.web.WebModule.start(WebModule.java:691) [web-glue.jar:na]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041) [web-core.jar:na]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024) [web-core.jar:na]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747) [web-core.jar:na]
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2278) [web-glue.jar:na]
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1924) [web-glue.jar:na]
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139) [web-glue.jar:na]
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122) [internal-api.jar:na]
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291) [internal-api.jar:na]
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352) [internal-api.jar:na]
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:497) [kernel.jar:na]
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219) [kernel.jar:na]
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491) [deployment-admin.jar:na]
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527) [kernel.jar:na]
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523) [kernel.jar:na]
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_17]
at javax.security.auth.Subject.doAs(Subject.java:356) [na:1.7.0_17]
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522) [kernel.jar:na]
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546) [kernel.jar:na]
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423) [kernel.jar:na]
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108) [kernel.jar:na]
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762) [kernel.jar:na]
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674) [kernel.jar:na]
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534) [kernel.jar:na]
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224) [kernel.jar:na]
at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297) [nucleus-grizzly-all.jar:na]
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246) [kernel.jar:na]
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564) [nucleus-grizzly-all.jar:na]
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544) [nucleus-grizzly-all.jar:na]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_17]
Caused by: java.lang.ClassNotFoundException: util.MyAuthenticationHandler
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1761) ~[war-util.jar:na]
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1611) ~[war-util.jar:na]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:236) ~[spring-core-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:392) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
... 57 common frames omitted
MyAuthenticationHandler类存在于包" util"在src文件夹中。 正如我之前所说的,之前一切都有效,而且我的代码中没有任何改变。
的applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
">
<!-- begin Spring Security config -->
<sec:global-method-security secured-annotations="enabled" />
<!-- Don't SSL encrypt static resources -->
<!-- <sec:http pattern="/resources/**" security="none"/> -->
<sec:http auto-config="true" access-denied-page="/faces/loginerror.jsp">
<!-- On Glassfish, dev ports are 8080 and 8181, whereas on
production its 80 and 443 -->
<sec:port-mappings>
<sec:port-mapping http="8080" https="8181"/>
</sec:port-mappings>
<sec:intercept-url
pattern="/faces/admin/**"
access="ROLE_ADMIN" requires-channel="https" />
<sec:intercept-url
pattern="/faces/users/**"
access="ROLE_USER, ROLE_ADMIN" requires-channel="https" />
<sec:intercept-url
pattern="/**"
access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<!-- Use O/S provided login window
<http-basic />
-->
<!-- Use custom form for login -->
<sec:form-login
login-processing-url="/j_spring_security_check"
login-page="/faces/login.jsp"
authentication-success-handler-ref="myAuthenticationHandler"
authentication-failure-url="/faces/loginerror.jsp"/>
<sec:logout logout-url="/j_spring_security_logout"
invalidate-session="true"
logout-success-url="/faces/index.jsp" />
</sec:http>
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider>
<sec:password-encoder ref="encoderBean">
<sec:salt-source user-property="username"/>
</sec:password-encoder>
<sec:jdbc-user-service data-source-ref="dataSource"
users-by-username-query=
"select username, password, enabled from expuser where username=?"
authorities-by-username-query=
"select username, authority from expuser where username=?" />
<!-- if not using a database for accounts, hard-code them here
<sec:user-service>
<sec:user name="admin" password="admin" authorities="ROLE_ADMIN, ROLE_MEMBER" />
<sec:user name="member" password="member" authorities="ROLE_MEMBER" />
</sec:user-service>
-->
</sec:authentication-provider>
</sec:authentication-manager>
<bean id="myAuthenticationHandler" class="util.MyAuthenticationHandler" />
<bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>
<bean id="encoderBean" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
<constructor-arg value="512" />
<property name="iterations" value="1024"/>
</bean>
<!-- Server managed connection pool accessed via JNDI -->
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/Datasource"/>
<!-- (Optional) Automatically receives and logs AuthenticationEvent messages -->
<bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>
</beans>
MyAuthenticationHandler.java:
package util;
import java.io.IOException;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
public class MyAuthenticationHandler extends
SimpleUrlAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
String userTargetUrl = "/faces/users/indexUser.jsp";
String adminTargetUrl = "/faces/admin/indexAdmin.jsp";
Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
if(roles.contains("ROLE_ADMIN")){
getRedirectStrategy().sendRedirect(request, response, adminTargetUrl);
}else if(roles.contains("ROLE_USER")){
getRedirectStrategy().sendRedirect(request, response, userTargetUrl);
}else{
super.onAuthenticationSuccess(request, response, authentication);
return;
}
}
}
提前致谢!
答案 0 :(得分:0)
使用Maven-&gt; Update Project意味着根据 pom.xml 文件更新项目属性。检查 Java构建路径和部署程序集。