前提・実現したいこと
AOPで全てのControllerのメソッド実行前に共通処理を組み込みたい。
発生している問題・エラーメッセージ
xmlを確認すると「ポイントカットが誤っています: error at ::0 formal unbound in pointcut」と警告が出されていて、実行できません。
↓エラーのスタックトレースです。
WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1188) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1132) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:811) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
該当のソースコード
組み込みたいメソッド
Java
1package com.mvc.test.service; 2 3import java.io.IOException; 4 5import javax.security.sasl.AuthenticationException; 6import javax.servlet.http.HttpServletRequest; 7import javax.servlet.http.HttpServletResponse; 8import javax.servlet.http.HttpSession; 9 10import org.aspectj.lang.JoinPoint; 11import org.aspectj.lang.annotation.Aspect; 12import org.aspectj.lang.annotation.Before; 13import org.springframework.beans.factory.annotation.Autowired; 14import org.springframework.stereotype.Service; 15 16import com.mvc.test.entity.BaseEntity; 17import com.mvc.test.repository.BaseRepository; 18 19@Aspect 20@Service 21public class AuthLogic { 22 23 @Autowired 24 private BaseRepository repositoryBase; 25 26 @Before("execution(* *..*Controller.*(..))") 27 public void auth( 28 JoinPoint joinpoitnt, 29 HttpSession session, 30 HttpServletRequest request , 31 HttpServletResponse response) { 32 33 //処理内容 34 35 } 36 37
servlet-context.xml
xml
1<?xml version="1.0" encoding="UTF-8"?> 2<beans:beans 3 xmlns="http://www.springframework.org/schema/mvc" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:aop="http://www.springframework.org/schema/aop" 6 xmlns:beans="http://www.springframework.org/schema/beans" 7 xmlns:context="http://www.springframework.org/schema/context" 8 xsi:schemaLocation="http://www.springframework.org/schema/mvc 9 https://www.springframework.org/schema/mvc/spring-mvc.xsd 10 http://www.springframework.org/schema/beans 11 https://www.springframework.org/schema/beans/spring-beans.xsd 12 http://www.springframework.org/schema/context 13 https://www.springframework.org/schema/context/spring-context.xsd 14 http://www.springframework.org/schema/aop 15 http://www.springframework.org/schema/aop/spring-aop.xsd"> 16 17 <!-- DispatcherServlet Context: defines this servlet's request-processing 18 infrastructure --> 19 20 <!-- Enables the Spring MVC @Controller programming model --> 21 <annotation-driven /> 22 <aop:aspectj-autoproxy /> 23 <aop:config proxy-target-class="true" /> 24 25 <!-- Handles HTTP GET requests for /resources/** by efficiently serving 26 up static resources in the ${webappRoot}/resources directory --> 27 <resources mapping="/resources/**" location="/resources/" /> 28 29 <!-- Resolves views selected for rendering by @Controllers to .jsp resources 30 in the /WEB-INF/views directory --> 31 <beans:bean 32 class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 33 <beans:property name="prefix" value="/WEB-INF/views/" /> 34 <beans:property name="suffix" value=".jsp" /> 35 </beans:bean> 36 37 <!-- fileuploadResolver --> 38 <beans:bean id="multipartResolver" 39 class="org.springframework.web.multipart.support.StandardServletMultipartResolver"> 40 </beans:bean> 41 42 <!-- <beans:bean class="com.mvc.test.err.AccountResolver" /> --> 43 44 <context:component-scan 45 base-package="com.mvc.test" /> 46 47</beans:beans>
root-context.xml
xml
1<?xml version="1.0" encoding="UTF-8"?> 2 3<beans 4 xmlns="http://www.springframework.org/schema/beans" 5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 6 xmlns:context="http://www.springframework.org/schema/context" 7 xmlns:jpa="http://www.springframework.org/schema/data/jpa" 8 xmlns:tx="http://www.springframework.org/schema/tx" 9 xmlns:jdbc="http://www.springframework.org/schema/jdbc" 10 xsi:schemaLocation="http://www.springframework.org/schema/beans 11 http://www.springframework.org/schema/beans/spring-beans.xsd 12 http://www.springframework.org/schema/data/jpa 13 http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 14 http://www.springframework.org/schema/tx 15 http://www.springframework.org/schema/tx/spring-tx.xsd 16 http://www.springframework.org/schema/jdbc 17 http://www.springframework.org/schema/jdbc/spring-jdbc.xsd 18 http://www.springframework.org/schema/context 19 http://www.springframework.org/schema/context/spring-context.xsd"> 20 21 <context:property-placeholder location="classpath:jdbc.properties" /> 22 <context:annotation-config /> 23 24 <jpa:repositories base-package="com.mvc.test.repository" /> 25 26 <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 27 28 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 29 <property name="driverClassName" value="${jdbc.driverClassName}" /> 30 <property name="url" value="${jdbc.url}" /> 31 <property name="username" value="${jdbc.username}" /> 32 <property name="password" value="${jdbc.password}" /> 33 </bean> 34 35 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 36 <property name="dataSource" ref="dataSource" /> 37 <property name="jpaVendorAdapter"> 38 <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 39 <property name="showSql" value="false" /> 40 <property name="database" value="POSTGRESQL" /> 41 </bean> 42 </property> 43 </bean> 44 45 <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 46 <property name="entityManagerFactory" ref="entityManagerFactory" /> 47 <property name="dataSource" ref="dataSource" /> 48 </bean> 49 50</beans>
試したこと
参考サイトを見て@Serviceを@Componentに変更したり、ポイントカットを見直して変えてみましたが、何も変わりませんでした。
参考サイト
http://www.mitchy-world.jp/java/spring/3_1_6.htm
補足情報(FW/ツールのバージョンなど)
開発はeclipse Oxygen、Springは4.3.21.RELEASEを使っています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/23 05:57