WEB.XML -
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/login-security.xml
/WEB-INF/spring/appServlet/login-servlet.xml
/WEB-INF/spring/appServlet/login-service.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
LOGIN-SECURITY.xml
<beans:import resource="login-service.xml"/>
<security:http auto-config="true">
<security:intercept-url pattern='/home*'
access='ROLE_USER,ROLE_ADMIN' />
<security:intercept-url pattern='/admin*'
access='ROLE_ADMIN' />
<security:form-login login-page='/login.jsp'
default-target-url='/home' authentication-failure-url='/login.jsp?error=true' />
<security:logout logout-success-url='/login.jsp' />
<security:anonymous username='guest'
granted-authority='ROLE_GUEST' />
<security:remember-me />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:jdbc-user-service
data-source-ref='myDataSource'
users-by-username-query="select username, password, 'true' as enabled from USER_DETAILS where username=?"
authorities-by-username-query="select USER_DETAILS.username , USER_AUTH.AUTHORITY as authorities from USER_DETAILS,USER_AUTH
where USER_DETAILS.username = ? AND USER_DETAILS.username=USER_AUTH.USERNAME"></security:jdbc-user-service>
</security:authentication-provider>
</security:authentication-manager>
LOGIN-SERVICE.xml
<beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<beans:property name="url" value="jdbc:oracle:thin:@localhost:1521:XE" />
<beans:property name="username" value="system" />
<beans:property name="password" value="oracle" />
LOGIN-SERVLET.xml
<context:component-scan base-package="com.poc.security" />
<bean id="internalResourceResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class='org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter' />
您能否提供您正在使用的整個web.xml以及您正在使用的Spring配置文件? – geoand
你可以請分享你的電子郵件ID,我想這將是很難分享堆棧溢出。謝謝。 –
它可能會更好地把它放在pastebin爲了讓其他用戶也能夠查看它 – geoand